imgutils.detect.halfbody

Overview:

Detect upper-half body in anime images.

Trained on dataset deepghs/anime_halfbody_detection with YOLOv8.

../../_images/halfbody_detect_demo.plot.py.svg

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

../../_images/halfbody_detect_benchmark.plot.py.svg

Note

Please note that the primary purpose of this tool is to crop upper-body images from illustrations. Therefore, the training data used mostly consists of single-person images, and the performance on images with multiple people is not guaranteed. If you indeed need to process images with multiple people, the recommended approach is to first use the imgutils.detect.person.detect_person() function to crop individuals, and then use this tool to obtain upper-body images.

detect_halfbody

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

Detect human upper-half body in anime images.

This function uses a YOLOv8 model to detect and localize upper-half bodies in anime-style images. It supports different model levels and versions for flexibility in speed and accuracy trade-offs.

Parameters:
  • image (ImageTyping) – The input image to perform detection on. Can be a file path, URL, or image data.

  • level (str) – The model level to use. Can be either ‘s’ (standard) or ‘n’ (nano). The ‘n’ model is faster with lower system overhead, while ‘s’ offers higher accuracy. Default is ‘s’.

  • 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 threshold are returned. Default is 0.5.

  • iou_threshold (float) – Intersection over Union (IoU) threshold for non-maximum suppression. Overlapping detections above this threshold are merged. Default is 0.7.

Returns:

A list of detections. Each detection is a tuple containing: - Bounding box coordinates as (x0, y0, x1, y1) - The string ‘halfbody’ (always) - The confidence score of the detection

Return type:

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

Raises:

ValueError – If an invalid level or version is provided.

Examples::
>>> from imgutils.detect import detect_halfbody, detection_visualize
>>>
>>> image = 'squat.jpg'
>>> result = detect_halfbody(image)  # detect it
>>> result
[((127, 21, 629, 637), 'halfbody', 0.9040350914001465)]
>>>
>>> # visualize it
>>> from matplotlib import pyplot as plt
>>> plt.imshow(detection_visualize(image, result))
>>> plt.show()