imgutils.detect.hand

Overview:

This module provides functionality for detecting human hands in anime images.

../../_images/hand_detect_demo.plot.py.svg

It uses YOLOv8 models trained on the deepghs/anime_hand_detection dataset from HuggingFace. The module offers a main function detect_hands() for hand detection in anime images, with options to choose different model levels and versions for balancing speed and accuracy.

This is an overall benchmark of all the hand detect models:

../../_images/hand_detect_benchmark.plot.py.svg

detect_hands

imgutils.detect.hand.detect_hands(image: str | PathLike | bytes | bytearray | BinaryIO | Image, level: str = 's', version: str = 'v1.0', model_name: str | None = None, conf_threshold: float = 0.35, iou_threshold: float = 0.7) List[Tuple[Tuple[int, int, int, int], str, float]][source]

Detect human hand points in anime images.

This function uses a YOLOv8 model to detect hands in the given anime image. It allows for configuration of the model level, version, and detection thresholds to suit different use cases.

Parameters:
  • image (ImageTyping) – Image to detect. Can be various types as defined by ImageTyping.

  • level (str) – The model level being used, either ‘s’ or ‘n’. ‘s’ (standard) offers higher accuracy, while ‘n’ (nano) provides faster processing.

  • version (str) – Version of the model to use. Default is ‘v1.0’.

  • model_name (Optional[str]) – Optional custom model name. If not provided, it’s constructed from version and level.

  • conf_threshold (float) – Confidence threshold for detections. Only detections with confidence above this value are returned. Default is 0.35.

  • iou_threshold (float) – Intersection over Union (IOU) threshold for non-maximum suppression. Detections with IOU above this value are considered overlapping and merged. Default is 0.7.

Returns:

A list of detection results. Each result is a tuple containing: - Bounding box coordinates as (x0, y0, x1, y1) - Class label (always ‘hand’ for this function) - Confidence score

Return type:

List[Tuple[Tuple[int, int, int, int], str, float]]

Raises:

May raise exceptions related to image loading or model inference.

Example:
>>> from PIL import Image
>>> image = Image.open('anime_image.jpg')
>>> results = detect_hands(image, level='s', conf_threshold=0.4)
>>> for bbox, label, conf in results:
...     print(f"Hand detected at {bbox} with confidence {conf}")