Skip to main content

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.

Metadata

Release files for crop-yolo-v8 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crop-yolo-v8 1.1.1
File Size Uploaded Provenance
crop_yolo_v8-1.1.1.tar.gz 4.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for crop-yolo-v8 1.1.1
File Interpreter ABI Platform
crop_yolo_v8-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / crop_yolo_v8-1.1.1.tar.gz

Download URL crop_yolo_v8-1.1.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
21f32c3a1da474374cfaf62356e6c37f4d26e543b4ba5e6e9fe08c912619a325
BLAKE2b-256 checksum
How to use checksums
e561e3d8d7ddfbc67888c4a5adc79dc720edd434a113be3b649110ec0eca44fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Darwin/23.5.0

Release files / crop_yolo_v8-1.1.1-py3-none-any.whl

Download URL crop_yolo_v8-1.1.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95a6e38c8c967448c276154413873f085dcbc27563f5f391b4a0eb1eb5081821
BLAKE2b-256 checksum
How to use checksums
8773b8970a1a5a5fa9caebc91b4660a2f2f0a6e040faaa4674c29b985dadd0af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Darwin/23.5.0

Security for crop-yolo-v8 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page