MediaPipe pose tracking in Python - klinke.studio

MediaPipe pose tracking in Python

browse sections

MediaPipe pose tracking in Python

Minimal example for running a pose model on a webcam stream and accessing landmarks. This keeps the loop simple: capture frame → convert color space → run model → read landmarks.

import cv2
import mediapipe as mp

mp_pose = mp.solutions.pose
pose = mp_pose.Pose(min_detection_confidence=0.5)
mp_drawing = mp.solutions.drawing_utils

cap = cv2.VideoCapture(0)

while cap.isOpened():
    success, image = cap.read()
    if not success:
        continue

    image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    results = pose.process(image_rgb)

    if results.pose_landmarks:
        # landmarks = results.pose_landmarks.landmark
        # do something with the data
        pass

    cv2.imshow('Pose Detection', image)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()