Skip to content

akiselevprivate/AutoCrop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutoCrop

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.

Installation

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 dependencies

Usage

Once installed, you can use the script to process and crop images in a specified folder.

Basic Command

python main.py <image_folder> [options]
  • <image_folder>: Path to the folder containing images you want to process.

Options

  • --device: Torch device to use (cuda if available, otherwise cpu by 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

Example

python main.py images --save_annotated

This 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.

How It Works:

  1. Image Input: The script reads images from the specified input folder.
  2. Detection Models: Pre-trained face and person detection models process the images.
  3. Cropping and Output: Images are cropped to the detected regions, with optional padding and annotations.
  4. Error Handling: The script logs issues such as blurry images, images with no detections, or multiple detections.

Output Metrics:

After processing, the script prints detailed metrics, including the number of successfully cropped images, blurry images, undetected images, and other relevant statistics.

License

This project is licensed under the MIT License.

About

AutoCrop is a versatile script designed to automatically crop people in images.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages