Human pose estimation is a cutting-edge pc imaginative and prescient expertise that transforms visible information into actionable insights about human motion. By using superior machine studying fashions like MediaPipe’s BlazePose and highly effective libraries reminiscent of OpenCV, builders can observe physique key factors with unprecedented accuracy. On this tutorial, we discover the seamless integration of those, demonstrating how Python-based frameworks allow refined pose detection throughout numerous domains, from sports activities analytics to healthcare monitoring and interactive functions.
First, we set up the important libraries:
!pip set up mediapipe opencv-python-headless matplotlib
Then, we import the vital libraries wanted for our implementation:
import cv2
import mediapipe as mp
import matplotlib.pyplot as plt
import numpy as np
We initialize the MediaPipe Pose mannequin in static picture mode with segmentation enabled and a minimal detection confidence of 0.5. It additionally imports utilities for drawing landmarks and making use of drawing types.
mp_pose = mp.options.pose
mp_drawing = mp.options.drawing_utils
mp_drawing_styles = mp.options.drawing_styles
pose = mp_pose.Pose(
static_image_mode=True,
model_complexity=1,
enable_segmentation=True,
min_detection_confidence=0.5
)
Right here, we outline the detect_pose operate, which reads a picture, processes it to detect human pose landmarks utilizing MediaPipe, and returns the annotated picture together with the detected landmarks. If landmarks are discovered, they’re drawn utilizing default styling.
def detect_pose(image_path):
picture = cv2.imread(image_path)
image_rgb = cv2.cvtColor(picture, cv2.COLOR_BGR2RGB)
outcomes = pose.course of(image_rgb)
annotated_image = image_rgb.copy()
if outcomes.pose_landmarks:
mp_drawing.draw_landmarks(
annotated_image,
outcomes.pose_landmarks,
mp_pose.POSE_CONNECTIONS,
landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style()
)
return annotated_image, outcomes.pose_landmarks
We outline the visualize_pose operate, which shows the unique and pose-annotated pictures facet by facet utilizing matplotlib. The extract_keypoints operate converts detected pose landmarks right into a dictionary of named keypoints with their x, y, z coordinates and visibility scores.
def visualize_pose(original_image, annotated_image):
plt.determine(figsize=(16, 8))
plt.subplot(1, 2, 1)
plt.title('Unique Picture')
plt.imshow(cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB))
plt.axis('off')
plt.subplot(1, 2, 2)
plt.title('Pose Estimation')
plt.imshow(annotated_image)
plt.axis('off')
plt.tight_layout()
plt.present()
def extract_keypoints(landmarks):
if landmarks:
keypoints = {}
for idx, landmark in enumerate(landmarks.landmark):
keypoints[mp_pose.PoseLandmark(idx).name] = {
'x': landmark.x,
'y': landmark.y,
'z': landmark.z,
'visibility': landmark.visibility
}
return keypoints
return None
Lastly, we load a picture from the desired path, detect and visualize human pose landmarks utilizing MediaPipe, after which extract and print the coordinates and visibility of every detected keypoint.
image_path="/content material/Screenshot 2025-03-26 at 12.56.05 AM.png"
original_image = cv2.imread(image_path)
annotated_image, landmarks = detect_pose(image_path)
visualize_pose(original_image, annotated_image)
keypoints = extract_keypoints(landmarks)
if keypoints:
print("Detected Keypoints:")
for title, particulars in keypoints.objects():
print(f"{title}: {particulars}")
On this tutorial, we explored human pose estimation utilizing MediaPipe and OpenCV, demonstrating a complete method to physique keypoint detection. We applied a strong pipeline that transforms pictures into detailed skeletal maps, masking key steps together with library set up, pose detection operate creation, visualization methods, and keypoint extraction. Utilizing superior machine studying fashions, we showcased how builders can rework uncooked visible information into significant motion insights throughout numerous domains like sports activities analytics and healthcare monitoring.
Right here is the Colab Notebook. Additionally, don’t overlook to observe us on Twitter and be a part of our Telegram Channel and LinkedIn Group. Don’t Overlook to hitch our 85k+ ML SubReddit.

Asif Razzaq is the CEO of Marktechpost Media Inc.. As a visionary entrepreneur and engineer, Asif is dedicated to harnessing the potential of Synthetic Intelligence for social good. His most up-to-date endeavor is the launch of an Synthetic Intelligence Media Platform, Marktechpost, which stands out for its in-depth protection of machine studying and deep studying information that’s each technically sound and simply comprehensible by a large viewers. The platform boasts of over 2 million month-to-month views, illustrating its recognition amongst audiences.