A Python-based tool for object detection and selective blurring using YOLOv7. This repository allows you to blur specific classes of objects in videos or images. It’s an ideal solution for anonymizing data in videos, protecting privacy, or focusing on certain objects.
- Python 3.6+ installed on your system.
- pip upgraded to the latest version.
Start by cloning this repository to your local machine:
git clone https://github.com/RizwanMunawar/yolov7-object-blurring.git
cd yolov7-object-blurring
Create a virtual environment to isolate dependencies and prevent conflicts with existing Python packages.
For Linux Users:
python3 -m venv yolov7objblurring
source yolov7objblurring/bin/activate
For Windows Users:
python3 -m venv yolov7objblurring
yolov7objblurring\Scripts\activate
Upgrade pip and install the required packages by running:
pip install --upgrade pip
pip install -r requirements.txt
Download the YOLOv7 pretrained weights and move them to the yolov7-object-blurring
folder.
Use the following commands to detect and blur objects in your video:
-
Basic Command (change
source
to the path of your video):python detect_and_blur.py --weights yolov7.pt --source "your_video.mp4" --blurratio 20
-
Blurring Specific Classes (e.g.,
person
class):python detect_and_blur.py --weights yolov7.pt --source "your_video.mp4" --classes 0 --blurratio 50
-
Hiding Detection Boxes (hides the bounding box for blurred areas):
python detect_and_blur.py --weights yolov7.pt --source "your_video.mp4" --classes 0 --blurratio 50 --hidedetarea
The output video will be saved in the directory: runs/detect/exp
. Each new run creates a new exp
folder with the results.
Objects Blurred A | Objects Blurred B | Hidden Detection Area |
---|---|---|
- YOLOv7 Project: https://github.com/WongKinYiu/yolov7
- OpenCV Documentation: https://opencv.org/
For more insights and tutorials:
- YOLOv7 Training on Custom Data
- Roadmap for Computer Vision Engineers
- YOLO vs YOLOv5: Which is Better?
- Develop Analytics Dashboards with Streamlit