Skip to content

RizwanMunawar/yolov7-object-blurring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YOLOv7 Object Blurring

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.

Prerequisites

  • Python 3.6+ installed on your system.
  • pip upgraded to the latest version.

Quick Start Guide

1. Clone the Repository

Start by cloning this repository to your local machine:

git clone https://github.com/RizwanMunawar/yolov7-object-blurring.git
cd yolov7-object-blurring

2. Set Up a Virtual Environment (Recommended)

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

3. Install Dependencies

Upgrade pip and install the required packages by running:

pip install --upgrade pip
pip install -r requirements.txt

4. Download YOLOv7 Model Weights

Download the YOLOv7 pretrained weights and move them to the yolov7-object-blurring folder.

5. Running the Code

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

6. Accessing Results

The output video will be saved in the directory: runs/detect/exp. Each new run creates a new exp folder with the results.


Example Results

Objects Blurred A Objects Blurred B Hidden Detection Area
Image A Image B Image C

Resources and Further Reading

Articles by the Author

For more insights and tutorials:


Connect with the Author

Follow more updates on Medium or connect on LinkedIn.

About

YOLOv7 Object Blurring Using PyTorch and OpenCV

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages