There are many scenarios in which you may want to blur detections from an object detection model. For example, consider a scenario where you are counting the number of cars going through a drive-through. With computer vision, you can both count the number of cars while blurring any faces that are present.
In this guide, we are going to walk you through how to blur predictions from a
Segment Anything Model (SAM)
model in a few lines of code using the open source supervision Python package.
We will:
1. Install supervision
2. Load data
3. Plot and blur predictions with a supervision BlurAnnotator
Without further ado, let's get started!
First, install the supervision pip package:
Once you have installed supervision, you are ready to load your data and start writing logic to filter detections.
First, we are going to load our dataset into a supervision.DetectionDataset() object. This object will contain information about all the images in a dataset. You can load datasets from many different model types, from YOLO to MMDetection. For this guide, we will use the
Segment Anything Model (SAM)
data loader.
You can load data using the following code:
Replace the ... with the response object from your model.
Supervision has a range of annotators that let you visualize detections from a computer vision model. For this guide, we are going to use the BlurAnnotator, which allows you to plot bounding boxes and blur their contents.
You can use the following code to plot predictions and blur their contents:
You can try the blur annotator on example images in the interactive playground below. Upload an image that contains any common object in the Microsoft COCO class list (i.e. vehicles, cats, dogs, cell phones), then run the workflow to see the objects blurred.
supervision provides an extensive range of functionalities for working with computer vision models. With supervision, you can:
1. Process and filter detections and segmentation masks from a range of popular models (YOLOv5, Ultralytics YOLOv8, MMDetection, and more).
2. Process and filter classifications.
3. Compute confusion matrices.
And more! To learn about the full range of functionality in supervision, check out the supervision documentation.