순서
마찬가지로 이전에 사용한 코드를 가져와서 추가 해주면 됩니다.
cap = cv2.VideoCapture(0)
## Setup mediapipe instance
with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:
while cap.isOpened():
ret, frame = cap.read()
# Recolor image to RGB
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image.flags.writeable = False
# Make detection
results = pose.process(image)
# Recolor back to BGR
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
#! Extract landmarks
try:
landmarks = results.pose_landmarks.landmark #to hold our different landmarks
print(landmarks) #we can see landmarks generate -> each of one of these represents a different coordinate or a different joint
except:
pass #don't have any detections or we have an error
#rather it's easier to just have a try accept block so if we don't make any detections then we can just pass
# Render detections
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
mp_drawing.DrawingSpec(color=(245,117,66), thickness=2, circle_radius=2),
mp_drawing.DrawingSpec(color=(245,66,230), thickness=2, circle_radius=2)
)
cv2.imshow('Mediapipe Feed', image)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Extract landmarks 부분의 주석을 봐주시면 됩니다!
len(landmarks)
33
for lndmrk in mp_pose.PoseLandmark:
print(lndmrk)
→ mapping for each one of our landmarks
→ grab one of these landmakrs our using this map
mp_pose.PoseLandmark.LEFT_SHOULDER
<PoseLandmark.LEFT_SHOULDER: 11>
landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value].visibility
0.29700446128845215
landmarks[mp_pose.PoseLandmark.LEFT_ELBOW.value]
x: 1.064361333847046
y: 1.0996811389923096
z: -1.223690390586853
visibility: 0.15188086032867432
여기 까지 하시면 좌표도 나올겝니다.