|
import cv2 |
|
import mediapipe as mp |
|
|
|
|
|
mp_pose = mp.solutions.pose |
|
mp_drawing = mp.solutions.drawing_utils |
|
|
|
|
|
pose = mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) |
|
|
|
|
|
cap = cv2.VideoCapture(0) |
|
|
|
while cap.isOpened(): |
|
ret, frame = cap.read() |
|
if not ret: |
|
break |
|
|
|
|
|
frame = cv2.flip(frame, 1) |
|
|
|
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) |
|
|
|
results = pose.process(rgb_frame) |
|
|
|
|
|
if results.pose_landmarks: |
|
mp_drawing.draw_landmarks(frame, results.pose_landmarks, mp_pose.POSE_CONNECTIONS) |
|
|
|
|
|
landmarks = results.pose_landmarks.landmark |
|
for i, landmark in enumerate(landmarks): |
|
print(f"Landmark {i}: x={landmark.x}, y={landmark.y}, z={landmark.z}") |
|
|
|
|
|
cv2.imshow('Pose Detection', frame) |
|
|
|
|
|
if cv2.waitKey(1) & 0xFF == ord('q'): |
|
break |
|
|
|
|
|
cap.release() |
|
cv2.destroyAllWindows() |
|
|