This Python script scans a directory for images and automatically deletes those that contain human figures. It uses OpenCV's Haar Cascade Classifier to detect humans in images.
- Detects human presence in images using a pre-trained model.
- Deletes images that contain humans.
- Supports common image formats (
.jpg,.jpeg,.png). - Fast and efficient processing using OpenCV.
Ensure you have Python installed and install the required dependencies using:
pip install opencv-python- Clone this repository or download the script.
- Place all your images inside a folder.
- Modify the script to set the correct
image_directorypath.
image_directory = 'path_to_your_images'- Run the script:
python detect_and_delete.py- The script loads a Haar Cascade Classifier (
haarcascade_fullbody.xml) to detect human figures. - It converts each image to grayscale and scans for human-like shapes.
- If a human is detected, the image is deleted from the directory.
Image1.jpg does not contain a human.
Deleted image: Image2.jpg
Image3.png does not contain a human.
-
If you want to detect faces instead of full-body figures, replace:
cascade_path = cv2.data.haarcascades + 'haarcascade_fullbody.xml'
with:
cascade_path = cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
-
The script is optimized for general human detection, but for higher accuracy, consider using deep learning models like YOLO, SSD, or Faster R-CNN.
This project is open-source and available under the MIT License.