realutils.detect.person
- Overview:
Detect persons in both real photo and anime images.
Trained with deepghs/anime_person_detection and open-sourced real photos datasets.
This is an overall benchmark of all the person detect models:
The models are hosted on huggingface - deepghs/real_person_detection.
detect_persons
- realutils.detect.person.detect_persons(image: str | PathLike | bytes | bytearray | BinaryIO | Image, model_name: str = 'person_detect_v0_s_yv11', conf_threshold: float = 0.35, iou_threshold: float = 0.7, **kwargs) List[Tuple[Tuple[int, int, int, int], str, float]] [source]
Detect persons in both real photo and anime images using YOLO models.
This function applies a pre-trained YOLO model to detect persons in the given anime image. It supports different model levels and versions, allowing users to balance between detection speed and accuracy.
- Parameters:
image (ImageTyping) – The input image for person detection. Can be various image types supported by ImageTyping.
model_name (str) – Optional custom model name. If provided, it overrides the auto-generated model name.
conf_threshold (float) – The confidence threshold for detections. Only detections with confidence scores above this threshold will be returned. Default is 0.35.
iou_threshold (float) – The Intersection over Union (IoU) threshold for non-maximum suppression. Detections with IoU above this threshold will be merged. Default is 0.7.
- Returns:
A list of detected persons. Each person is represented by a tuple containing: - Bounding box coordinates as (x0, y0, x1, y1) - The string ‘person’ (as this function only detects persons) - The confidence score of the detection
- Return type:
List[Tuple[Tuple[int, int, int, int], str, float]]
- Example:
>>> from realutils.detect import detect_persons >>> >>> detect_persons('yolo/solo.jpg') [((0, 30, 398, 599), 'person', 0.926707923412323)] >>> detect_persons('yolo/2girls.jpg') [((0, 74, 760, 1598), 'person', 0.7578195333480835), ((437, 33, 1200, 1600), 'person', 0.6875205039978027)] >>> detect_persons('yolo/3+cosplay.jpg') [((106, 69, 347, 591), 'person', 0.8794167041778564), ((326, 14, 592, 534), 'person', 0.8018194437026978), ((167, 195, 676, 675), 'person', 0.5351650714874268)] >>> detect_persons('yolo/multiple.jpg') [((1305, 441, 1891, 1534), 'person', 0.8789498805999756), ((206, 191, 932, 1533), 'person', 0.8423126935958862), ((1054, 170, 1417, 1055), 'person', 0.8138357996940613), ((697, 659, 1473, 1534), 'person', 0.7926754951477051), ((685, 247, 1128, 1526), 'person', 0.5261526703834534), ((690, 251, 1125, 1126), 'person', 0.4193646311759949)]
>>> from imgutils.detect import detection_visualize >>> from matplotlib import pyplot as plt >>> >>> image = 'yolo/solo.jpg' >>> result = detect_persons(image) >>> >>> # visualize it >>> plt.imshow(detection_visualize(image, result)) >>> plt.show()