This Python project detects nude and semi-nude images using the OpenNSFW2 library, blurs them, and organizes them into separate folders. It is designed to help automate the process of identifying and handling sensitive content in image datasets.
- Features
- Prerequisites
- Installation
- Usage
- Folder Structure
- Customization
- Troubleshooting
- Contributing
- License
- Detect Nude/Semi-Nude Images: Uses the OpenNSFW2 model to classify images based on their NSFW probability.
- Blur Unsafe Images: Applies a Gaussian blur to detected nude/semi-nude images to anonymize sensitive content.
- Organize Images:
- Moves original unsafe images to a dedicated folder (
nude_images). - Moves blurred versions of unsafe images to another folder (
blurred_images).
- Moves original unsafe images to a dedicated folder (
- Threshold-Based Filtering: Allows you to adjust the sensitivity of detection using a configurable threshold.
Before running the application, ensure you have the following installed:
- Python 3.7 or higher
opennsfw2(for NSFW detection)Pillow(for image processing)shutil(for file operations)
You can install the required dependencies using the following command:
pip install opennsfw2 pillow-
Clone this repository:
git clone https://github.com/wprashed/guardianai cd guardianai -
Install the required dependencies:
pip install -r requirements.txt
-
Create the necessary folders:
mkdir input_images nude_images blurred_images -
Place your images in the
input_imagesfolder.
-
Run the script:
python app.py
-
The script will:
- Process all images in the
input_imagesfolder. - Move detected nude/semi-nude images to the
nude_imagesfolder. - Blur the detected images and move the blurred versions to the
blurred_imagesfolder.
- Process all images in the
-
Adjust the sensitivity of detection by modifying the
thresholdvariable in the script:threshold = 0.6 # Default value; adjust between 0 and 1
The project uses the following folder structure:
project/
├── input_images/ # Place your images here
├── nude_images/ # Original nude/semi-nude images will be moved here
├── blurred_images/ # Blurred nude/semi-nude images will be moved here
├── temp_blurred/ # Temporary folder for blurred images (auto-cleaned)
├── app.py # The Python script
├── README.md # Project documentation
└── requirements.txt # List of dependencies
-
Adjust Blur Intensity: Modify the
radiusparameter in theblur_image()function to control the strength of the blur:blurred_img = img.filter(ImageFilter.GaussianBlur(radius=20)) # Default radius
-
Change Detection Threshold: Adjust the
thresholdvariable in theprocess_images()function to make the detection stricter or more lenient:threshold = 0.6 # Higher values make detection stricter
-
Output Folder Names: Change the folder names in the
process_images()function if you want to use different folder names:nude_folder = "nude_images" blurred_folder = "blurred_images"
-
Error: Pillow Not Installed: If you encounter an error related to
Pillow, install it using:pip install pillow
-
Error: File Overwrite Issues: Ensure filenames are unique or modify the script to append a suffix to filenames when saving blurred images.
-
Temporary Folder Cleanup: The
temp_blurredfolder is automatically deleted if empty. If issues persist, manually delete it after running the script.
Contributions are welcome! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Submit a pull request with a clear description of your changes.
This project is licensed under the MIT License. Feel free to use, modify, and distribute it as per the terms of the license.
- Thanks to the creators of the OpenNSFW2 library for making it publicly available.
- Special thanks to the
Pillowlibrary for providing robust image processing capabilities.