Skip to main content

put yolov8m/n/x.pt in ~/.yolov8 and run

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_yolo_v8-1.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crop_yolo_v8-1.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file crop_yolo_v8-1.1.0.tar.gz.

File metadata

  • Download URL: crop_yolo_v8-1.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.5.0

File hashes

Hashes for crop_yolo_v8-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d71b63ce9789f3b109f81b1682c765fb0d7298a7e4d959ea0f1b8a336ee6c690
MD5 f8875b902823164e44d8d769c19d39d5
BLAKE2b-256 2b0c78b9fd4622511bf64ca9e8c1feadb8f2caceac27f130259a1a5d8825e8cd

See more details on using hashes here.

File details

Details for the file crop_yolo_v8-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: crop_yolo_v8-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.5.0

File hashes

Hashes for crop_yolo_v8-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fbb31739fa6646a5415d15675b95795577811682b040eb6cba45026ae094f05b
MD5 d61ab7abb2a3545223dca1d116765157
BLAKE2b-256 eaa3a46d9312a15f0ee3a9df1ef1a110a53026934acd4a36099ce8895877c014

See more details on using hashes here.

Supported by

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