The following official sample code is working well. But the code only find one pose in a picture or movies. https://github.com/google/mediapipe/blob/master/docs/solutions/pose.md
import cv2
import mediapipe as mp
import numpy as np
mp_drawing = mp.solutions.drawing_utils
mp_drawing_styles = mp.solutions.drawing_styles
mp_pose = mp.solutions.pose
# For webcam input:
cap = cv2.VideoCapture(0)
with mp_pose.Pose( # <-- Does not have "max_poses" parameter
min_detection_confidence=0.5,
min_tracking_confidence=0.5) as pose:
while cap.isOpened():
success, image = cap.read()
if not success:
print("Ignoring empty camera frame.")
# If loading a video, use 'break' instead of 'continue'.
continue
# To improve performance, optionally mark the image as not writeable to
# pass by reference.
image.flags.writeable = False
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = pose.process(image)
# Draw the pose annotation on the image.
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
mp_drawing.draw_landmarks(
image,
results.pose_landmarks,
mp_pose.POSE_CONNECTIONS,
landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style())
# Flip the image horizontally for a selfie-view display.
cv2.imshow('MediaPipe Pose', cv2.flip(image, 1))
if cv2.waitKey(5) & 0xFF == 27:
break
cap.release()
According to another document, it guides us to use PoseLandmarkerOptions() which arrow us to change it by num_poses but mp.solutions.pose.Pose() above code does not have the option. I'd like to reuse the code with minimun modification.
Thank you,
MediaPipe Pose currently detects only one pose per image by design. If you're looking to detect multiple poses, you might have to look for workarounds, like segmenting the input image into multiple parts and running Pose detection on each. However, directly through the API, there isn’t a max_poses option available as of the latest update. This means you're limited to detecting one pose at a time with the straightforward approach provided in the MediaPipe solutions. Keep an eye on future updates for any changes!