AutoCrop is a versatile script designed to automatically crop people in images. It leverages pre-trained models for face and person detection to create clean and focused image outputs, making it ideal for preprocessing datasets or enhancing image content for character lora training datasets.
To get started, clone the repository and install the necessary dependencies:
git clone https://github.com/akiselevprivate/AutoCrop.git
cd AutoCrop
# create an enviroment if needed
pip install -r requirements.txt # Install all dependenciesOnce installed, you can use the script to process and crop images in a specified folder.
python main.py <image_folder> [options]<image_folder>: Path to the folder containing images you want to process.
--device: Torch device to use (cudaif available, otherwisecpuby default).--save_yolo_output: Save YOLO detection outputs (default:False).--max_crop_resolution: Maximum resolution for cropped images (default:1024).--min_crop_resolution: Minimum resolution for cropped images (default:1024).--face_padding: Padding around the detected face (default:0.2).--person_padding: Padding around the detected person (default:0.02).--save_annotated: Save images annotated with crop data (default:False).--use_original_filename: Save annotated images with their original filenames (default:False).--annotated_save_path: Directory for annotated images (default:annotated).--results_path: Directory for cropped images (default:results).--blur_threshold: Threshold for blurry image detection (default:20).
Note: blur detection is not great, use it to filter very blurry images
python main.py images --save_annotatedThis will process all images in the images/ folder, save annotated images in the default annotated folder, and save cropped images in the cropped_images folder.
- Image Input: The script reads images from the specified input folder.
- Detection Models: Pre-trained face and person detection models process the images.
- Cropping and Output: Images are cropped to the detected regions, with optional padding and annotations.
- Error Handling: The script logs issues such as blurry images, images with no detections, or multiple detections.
After processing, the script prints detailed metrics, including the number of successfully cropped images, blurry images, undetected images, and other relevant statistics.
This project is licensed under the MIT License.