Mediapipe + openCV: for a frame of video I want to extract the coordinates of 33 keypoints of pose detection in a single list

100 views Asked by At

So I am new to working with mediapipe and extremely confused in how to use mediapipe pose detector. I have a video, and I am using openCV to access the frames of that video and the using pose() to get all the keypoints of the video. sounds good? but the optput is not a list or anything its something else 'NormalizedLandmark' and i just cannot iterate it.

what I want to do is:

  1. access the video one frame at a time
  2. while accessing the first frame use pose() function to get all four (x,t,z,V) coordinates of the 33 keypoints
  3. put these 33*4 elements seperated by commas in one list
  4. access the second frame and repeat the process untill all frames are over
  5. put all these lists in another list.

let no. of frames are 204 then, output shape will be (204,132) 132 because 4 coordinates and 33 poses, 33*4=132

How I am trying to do this is:


lm_list = []
cap = cv2.VideoCapture('/content/drive/MyDrive/Sample poses/standing p1.mp4')


while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break

    # Convert the frame to RGB
    frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    result = pose.process(frame_rgb)


    if result.pose_landmarks:
        for idx, landmark in enumerate(result.pose_landmarks.landmark):
            lm_list.append([landmark.x, landmark.y, landmark.z, landmark.visibility])

Would be a great help!

0

There are 0 answers