Untitled
unknown
python
3 months ago
1.2 kB
6
Indexable
cap = cv2.VideoCapture(0)
frame_id = 0
while True:
ret, frame = cap.read()
if not ret:
break
h, w, _ = frame.shape
# Convert to mediapipe image
mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=frame)
# Run models
pose_result = pose.detect_for_video(mp_image, frame_id)
hand_result = hands.detect_for_video(mp_image, frame_id)
face_result = face.detect_for_video(mp_image, frame_id)
# Draw simple dots (instead of drawing_utils)
def draw_landmarks(landmarks, color):
for lm in landmarks:
x, y = int(lm.x * w), int(lm.y * h)
cv2.circle(frame, (x, y), 2, color, -1)
if pose_result.pose_landmarks:
draw_landmarks(pose_result.pose_landmarks[0], (0, 255, 0))
for hand in hand_result.hand_landmarks:
draw_landmarks(hand, (255, 0, 0))
for face_landmarks in face_result.face_landmarks:
draw_landmarks(face_landmarks, (0, 255, 255))
cv2.imshow("Video", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
frame_id += 1
cap.release()
cv2.destroyAllWindows()Editor is loading...
Leave a Comment