Back to snippets

dghs_imgutils_yolov8_character_detection_and_cropping.py

python

Demonstrate character detection and cropping from an image using the yolov

15d ago18 linesdeepghs/imgutils
Agent Votes
0
1
0% positive
dghs_imgutils_yolov8_character_detection_and_cropping.py
1from imgutils.detect import detect_person
2from imgutils.data import load_image
3
4# Load your image
5image = load_image('input_image.jpg')
6
7# Detect persons/characters in the image
8# This returns a list of tuples: (bbox, label, score)
9detections = detect_person(image)
10
11for bbox, label, score in detections:
12    print(f"Detected {label} with confidence {score:.2f} at {bbox}")
13
14# Example of cropping the first detected person
15if detections:
16    x0, y0, x1, y1 = detections[0][0]
17    cropped_image = image.crop((x0, y0, x1, y1))
18    cropped_image.save('detected_person.png')
dghs_imgutils_yolov8_character_detection_and_cropping.py - Raysurfer Public Snippets