자세 추정
자세 추정
from ultralytics import YOLO
model = YOLO('yolo11n-pose.pt')
import cv2 as cv
img = cv.imread('bus_stop.jpg')
results = model(img)
키포인트 (Keypoints)
keypoint_names = [
"Nose", "Left Eye", "Right Eye", "Left Ear", "Right Ear",
"Left Shoulder", "Right Shoulder", "Left Elbow", "Right Elbow",
"Left Wrist", "Right Wrist", "Left Hip", "Right Hip",
"Left Knee", "Right Knee", "Left Ankle", "Right Ankle"
]
자세 추정 결과 시각화
from PIL import Image, ImageDraw, ImageFont
try:
font = ImageFont.truetype("NanumGothic.ttf", 20)
except IOError:
font = ImageFont.load_default()
result = results[0]
kpts = result.keypoints.data.cpu().numpy()
img_bbox = Image.fromarray(cv.cvtColor(img, cv.COLOR_BGR2RGB))
draw = ImageDraw.Draw(img_bbox)
for kpt in kpts:
for j in range(len(kpt)):
x, y, conf = kpt[j]
if conf > 0.5:
draw.circle((x, y), radius=3, fill="#00FF00")
draw.text((x, y), f'{keypoint_names[j]}', font=font, fill="#00FF00")
img_bbox