Skip to main content

CLI tool to crop people from images using YOLOvX

Project description

YOLOv8 Person Cropping Tool

This tool uses YOLOv8 to detect and crop persons from images. It's designed to process multiple images, optionally searching recursively through directories, and can crop either the largest detected person or all detected persons in each image.

Features

  • Uses YOLOv8 for accurate person detection
  • Supports multiple YOLOv8 models (yolov8x.pt, yolov8m.pt, yolov8s.pt)
  • Processes images in parallel for faster execution
  • Allows recursive directory search
  • Option to crop all detected persons or just the largest one
  • Adds customizable margin to cropped images
  • Saves images with no detected persons in a separate directory
  • Option to remove small images after processing

Installation

  1. Clone this repository
  2. Install the required dependencies:
pip install ultralytics rich typer opencv-python
  1. Ensure you have the YOLOv8 models in your home directory under a yolov8 folder.

Usage

Run the script using the following command:

python main.py [OPTIONS]

Options

  • --margin-percentage INTEGER: Margin percentage for bounding box (default: 3, recommended range: 0-10)
  • --model-size INTEGER: Model size (default: 640, recommended: 320, 640, or 1280)
  • --model TEXT: YOLOv8 model to use (options: yolov8x.pt, yolov8m.pt, yolov8s.pt)
  • --recursive / --no-recursive: Search for images recursively (default: False)
  • --crop-all / --no-crop-all: Crop all detected persons instead of just the largest (default: False)

How it works

  1. The script prompts you to select an input directory.
  2. It processes all images in the selected directory (and subdirectories if recursive option is enabled).
  3. Detected persons are cropped from the images with the specified margin.
  4. Cropped images are saved in a 'cropped' subdirectory within the input directory.
  5. Images with no detected persons are saved in a 'no-person' subdirectory.
  6. After processing, you have the option to remove small images based on a size threshold.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crop_people_cli-1.4.1.tar.gz (76.3 kB view details)

Uploaded Source

Built Distribution

crop_people_cli-1.4.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file crop_people_cli-1.4.1.tar.gz.

File metadata

  • Download URL: crop_people_cli-1.4.1.tar.gz
  • Upload date:
  • Size: 76.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for crop_people_cli-1.4.1.tar.gz
Algorithm Hash digest
SHA256 f8e4139fd9281524c1610cfbb792000fd90932cf5dfa9dc8c8a3188f48695bb7
MD5 e84d40781f195f5832baeaf8b516fbb3
BLAKE2b-256 8f348d491647d28c791feb85182b43bd35e669f43139136c0fc1a8fa5e92679e

See more details on using hashes here.

File details

Details for the file crop_people_cli-1.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for crop_people_cli-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b12b5073798c8bf59cf1d237ca8940062b851886662885f5b7cd7bdb2e053029
MD5 9e19da669095e61b843e90a2d725779c
BLAKE2b-256 a6f0aa27579609d2b4a890543c8e64a6e94e60c4598ebaccb962907b7116f9d0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page