반응형

YOLO를 이용해 포즈를 추정해 보자.

 

from ultralytics import YOLO

kpt_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"]

model = YOLO("yolo26n-pose.pt")  # "yolo26n-pose.pt"가 없다면 자동으로 다운로드 받는다
results = model("palvin1.png", save=True)

print(f"Length of results: {len(results)}")
# 1개의 이미지만 사용했으므로 results에는 1개의 원소만 있다

# Access the results
for result in results: # results에는 1개의 원소만 있기 때문에 for 루프를 사용하는 의미는 없다
    xy = result.keypoints.xy  # x and y coordinates
    xyn = result.keypoints.xyn  # normalized
    kpts = result.keypoints.data  # x, y, visibility (if available)
    
    print(f"Number of people: {len(result)}")
        
    for i, kpt in enumerate(kpts):
        print(f"Confidence: {result.boxes.conf[i]}")
        for name, k in zip(kpt_names, kpt):
            if k[2] > 0.3: # k[2]: visibility
                print(f"{name} is at {k}")
            else:
                print(f"{name} is not visible")
        print()

 

 

 

 

 

 

 

 

※ 참고

Predict

Pose Estimation

YOLO8 OpenCV

 

반응형
Posted by J-sean
: