imgutils.detect.eye

Overview:

Detect eyes in anime images.

Trained on dataset deepghs/anime_eye_detection with YOLOv8.

../../_images/eye_detect_demo.plot.py.svg

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

../../_images/eye_detect_benchmark.plot.py.svg

detect_eyes

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

Detect human eyes in anime images.

This function uses a YOLOv8 model to detect eyes in the given anime image. It supports different model levels and versions, allowing for a trade-off between speed and accuracy.

Parameters:
  • image (ImageTyping) – The input image for eye detection. Can be various image types supported by ImageTyping.

  • level (str) – The model level to use. Can be either ‘s’ (for higher accuracy) or ‘n’ (for faster processing). 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 using version and level.

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

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

Returns:

A list of detected eyes. Each detection is represented by a tuple containing: - Bounding box coordinates as (x0, y0, x1, y1) - Detection class (always ‘eye’ for this function) - Confidence score of the detection

Return type:

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

Raises:

May raise exceptions related to image loading or model prediction (from yolo_predict function).

Examples::
>>> from imgutils.detect import detect_eyes, detection_visualize
>>>
>>> image = 'squat.jpg'
>>> result = detect_eyes(image)  # detect it
>>> result
[((297, 239, 341, 271), 'eye', 0.7760562896728516), ((230, 289, 263, 308), 'eye', 0.7682342529296875)]
>>>
>>> # visualize it
>>> from matplotlib import pyplot as plt
>>> plt.imshow(detection_visualize(image, result))
>>> plt.show()