Reference for ultralytics/solutions/object_blurrer.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/object_blurrer.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.solutions.object_blurrer.ObjectBlurrer
Bases: BaseSolution
A class to manage the blurring of detected objects in a real-time video stream.
This class extends the BaseSolution class and provides functionality for blurring objects based on detected bounding boxes. The blurred areas are updated directly in the input image, allowing for privacy preservation or other effects.
Attributes:
Name | Type | Description |
---|---|---|
blur_ratio |
int
|
The intensity of the blur effect applied to detected objects (higher values create more blur). |
iou |
float
|
Intersection over Union threshold for object detection. |
conf |
float
|
Confidence threshold for object detection. |
Methods:
Name | Description |
---|---|
process |
Applies a blurring effect to detected objects in the input image. |
extract_tracks |
Extracts tracking information from detected objects. |
display_output |
Displays the processed output image. |
Examples:
>>> blurrer = ObjectBlurrer()
>>> frame = cv2.imread("frame.jpg")
>>> processed_results = blurrer.process(frame)
>>> print(f"Total blurred objects: {processed_results.total_tracks}")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Any
|
Keyword arguments passed to the parent class and for configuration. blur_ratio (float): Intensity of the blur effect (0.1-1.0, default=0.5). |
{}
|
Source code in ultralytics/solutions/object_blurrer.py
process
Apply a blurring effect to detected objects in the input image.
This method extracts tracking information, applies blur to regions corresponding to detected objects, and annotates the image with bounding boxes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im0
|
ndarray
|
The input image containing detected objects. |
required |
Returns:
Type | Description |
---|---|
SolutionResults
|
Object containing the processed image and number of tracked objects. - plot_im (numpy.ndarray): The annotated output image with blurred objects. - total_tracks (int): The total number of tracked objects in the frame. |
Examples:
>>> blurrer = ObjectBlurrer()
>>> frame = cv2.imread("image.jpg")
>>> results = blurrer.process(frame)
>>> print(f"Blurred {results.total_tracks} objects")