SafeVision is a sophisticated Python script designed to detect and blur nudity in both images and videos. By harnessing advanced computer vision and deep learning techniques, SafeVision ensures that potentially sensitive or inappropriate content is effectively obscured, promoting safer and more appropriate media sharing and consumption. This README file provides comprehensive instructions on setting up and utilizing SafeVision effectively.
Clone the Repository:
git clone https://github.com/im-syn/safevision.git
cd safevision
Install Dependencies:
pip install -r requirements.txt
Download the Model:
best.onnx
model is placed in the Models
directory.-i
or --input
: Path to the input image or video (required).-o
or --output
: Path to save the censored image or video. If not provided, a default path will be used.-b
or --blur
: Apply blur to NSFW regions instead of drawing boxes.-e
or --exception
: Path to the blur exception rules file.-fbr
or --full_blur_rule
: Number of exposed boxes to trigger full image blur.Detect nudity and draw boxes:
python main.py -i path/to/media.jpg
Detect nudity and blur detected regions:
python main.py -i path/to/media.jpg -b
Specify output path:
python main.py -i path/to/media.jpg -o path/to/output.jpg
Use exception rules file:
python main.py -i path/to/media.jpg -e path/to/BlurException.rule
Set full blur rule and use exception rules file:
python main.py -i path/to/media.jpg -e path/to/BlurException.rule -fbr 25
BlurException.rule
)FACE_MALE = false
FACE_FEMALE = false
ARMPITS_COVERED = false
FEET_COVERED = false
BUTTOCKS_COVERED = false
BELLY_COVERED = false
FEMALE_GENITALIA_COVERED = false
FEMALE_BREAST_COVERED = false
ANUS_COVERED = false
MALE_GENITALIA_EXPOSED = true
MALE_BREAST_EXPOSED = true
ANUS_EXPOSED = true
FEET_EXPOSED = false
ARMPITS_EXPOSED = true
FEMALE_GENITALIA_EXPOSED = true
FEMALE_BREAST_EXPOSED = true
BUTTOCKS_EXPOSED = true
BELLY_EXPOSED = false
In the BlurException.rule
file, false
indicates that the corresponding body part will not be blurred, while true
indicates that it will be blurred.
-vo
or --video_output
: Path to the video output folder. Default is 'video_output'.-r
or --rule
: Blur rule in the format 'percentage/count'.Process video and draw boxes:
python main.py -i path/to/video.mp4 -t video
Process video and blur detected regions:
python main.py -i path/to/video.mp4 -t video -b
Specify video output folder:
python main.py -i path/to/video.mp4 -t video -vo path/to/video_output
Use blur rule:
python main.py -i path/to/video.mp4 -t video -r 50/10
The video processing follows a similar structure to image processing, with additional steps for handling frames and creating videos.
The script processes an input image or video to detect and blur nudity based on a trained ONNX model. It includes the following main components:
Image/Video Preprocessing:
Model Inference:
NudeDetector
class uses ONNX Runtime to load the model and perform inference to detect nudity.Postprocessing:
Blurring and Drawing Boxes:
The script ensures necessary directories exist for saving output images and videos.
SafeVision provides a robust solution for detecting and blurring nudity in images and videos, making it a valuable tool for content moderation and safe media sharing. Follow the instructions in this README to set up and use SafeVision effectively. If you have any questions or issues, please refer to the documentation or contact me.