MediaPipe Pose helps computers find and track body parts in pictures or videos. It makes it easy to understand human poses without complex setup.
0
0
MediaPipe Pose in Computer Vision
Introduction
You want to count how many times someone raises their hand in a video.
You want to check if someone is doing an exercise correctly by watching their body movements.
You want to create a game that reacts when a player moves their arms or legs.
You want to analyze dance moves by tracking body positions.
You want to help people with physical therapy by monitoring their posture.
Syntax
Computer Vision
import mediapipe as mp import cv2 mp_pose = mp.solutions.pose pose = mp_pose.Pose() cap = cv2.VideoCapture(0) while cap.isOpened(): success, image = cap.read() if not success: break image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) results = pose.process(image_rgb) if results.pose_landmarks: mp.solutions.drawing_utils.draw_landmarks( image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS) cv2.imshow('MediaPipe Pose', image) if cv2.waitKey(5) & 0xFF == 27: break pose.close() cap.release() cv2.destroyAllWindows()
Call pose.process() on an RGB image to get pose landmarks.
Use mp.solutions.drawing_utils.draw_landmarks() to draw the detected pose on the image.
Examples
This example shows how to set up MediaPipe Pose for single images instead of video.
Computer Vision
import mediapipe as mp mp_pose = mp.solutions.pose pose = mp_pose.Pose(static_image_mode=True) # Use static_image_mode=True for single images
This example shows how to access the x coordinate of the left wrist from detected landmarks.
Computer Vision
results = pose.process(image_rgb) if results.pose_landmarks: landmarks = results.pose_landmarks.landmark print(f"Left wrist x: {landmarks[mp_pose.PoseLandmark.LEFT_WRIST].x}")
Sample Model
This program captures 10 frames from the webcam and prints if a pose was detected in each frame.
Computer Vision
import mediapipe as mp import cv2 mp_pose = mp.solutions.pose pose = mp_pose.Pose() cap = cv2.VideoCapture(0) frame_count = 0 while cap.isOpened() and frame_count < 10: success, image = cap.read() if not success: break image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) results = pose.process(image_rgb) if results.pose_landmarks: print(f"Frame {frame_count + 1}: Pose landmarks detected") else: print(f"Frame {frame_count + 1}: No pose detected") frame_count += 1 pose.close() cap.release() cv2.destroyAllWindows()
OutputSuccess
Important Notes
Make sure your camera is connected and accessible before running the code.
MediaPipe Pose works best with clear views of the whole body.
Use static_image_mode=True for processing single images instead of video streams.
Summary
MediaPipe Pose detects body landmarks in images or videos.
It helps track human poses easily without complex setup.
You can use it for fitness, games, or any app needing body movement understanding.