Access specific Pose Landmarker Task API on Python

117 views Asked by At

I can't access to a specific landmarks with the new API using "vision.PoseLandmarker"

I used to use

import cv2
import mediapipe as mp

mp_pose = mp.solutions.pose

mp_drawing = mp.solutions.drawing_utils
cap = cv2.VideoCapture("video.mp4")

with mp_pose.Pose(
    static_image_mode = False) as pose:

if results.pose_landmarks is not None:
                
                x1 = int(results.pose_landmarks.landmark[16].x * width)
                y1 = int(results.pose_landmarks.landmark[16].y * height)

I tried use the official guide:

https://github.com/googlesamples/mediapipe/blob/main/examples/pose_landmarker/python/%5BMediaPipe_Python_Tasks%5D_Pose_Landmarker.ipynb

but it was impossible

2

There are 2 answers

0
leo_nidas300 On BEST ANSWER

The method to get a specific landmark with the new API is:

x1 = int(results.pose_landmarks[0][mp_pose.PoseLandmark.NOSE].x * width)

enter image description here

0
Jen Person On

According to the API reference, the detect method returns a PoseLandmarkerResult object with three properties: pose_landmarks, pose_world_landmarks, and the optional segmentation_masks:

mp.tasks.vision.PoseLandmarkerResult(
    pose_landmarks: List[List[landmark_module.NormalizedLandmark]],
    pose_world_landmarks: List[List[landmark_module.Landmark]],
    segmentation_masks: Optional[List[image_module.Image]] = None
)

So to get the x coordinate of a specific landmark, for example, you can do the following:

detection_result.pose_landmarks[0][0].x