Spaces:
Sleeping
Sleeping
File size: 1,473 Bytes
3910587 0a3b080 3910587 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import supervision as sv
from ultralytics import YOLO
from PIL import Image
import gradio as gr
import numpy as np
import cv2
import urllib
# load pre-trained vision model
model2 = YOLO("yolo11s-pose.pt")
# build pose annotator
def pose_annotate(image:str, pose_annotator:str) -> Image.Image:
"""
Annotates human postures detected in an image
Args:
image: the path to the image file
pose_annotator: the type of annotator to use
Returns:
annotated image
"""
# load the input image
image = cv2.imread(image)
# run object detection on the image
result = model2(image)[0]
# detect keypoints in image
key_points = sv.KeyPoints.from_ultralytics(result)
if pose_annotator == "Vertex":
vertex_annotator = sv.VertexAnnotator(
color=sv.Color.GREEN,
radius=10
)
annotated_frame = vertex_annotator.annotate(
scene=image.copy(),
key_points=key_points
)
elif pose_annotator == "Edge":
edge_annotator = sv.EdgeAnnotator(
color=sv.Color.GREEN,
thickness=5
)
annotated_frame = edge_annotator.annotate(
scene=image.copy(),
key_points=key_points
)
elif pose_annotator == "Vertexlabel":
vertex_label_annotator = sv.VertexLabelAnnotator(
color=sv.Color.GREEN,
text_color=sv.Color.BLACK,
border_radius=5
)
annotated_frame = vertex_label_annotator.annotate(
scene=image.copy(),
key_points=key_points
)
return annotated_frame
|