2 years ago

#70764

test-img

Teodor Apostol

Cant print X coords of landmark while from video, but can while from photo Mediapipe

I want to print the coords of a landmark from webcam, but I keep getting the error that "NoneType" object is not subscriptable, but when I change the code just a bit, to get the same coord of the same landmark, but from a photo, it is able to print it.

Code:

import mediapipe as mp
import cv2
mpDraw = mp.solutions.drawing_utils
mpPose = mp.solutions.pose
pose = mpPose.Pose()
cap = cv2.imread("/Users/teodor/Desktop/pose.jpg")
#cap = cv2.VideoCapture(0)

while True:
  #ret, img = cap.read()
  img = cap
  imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  results = pose.process(imgRGB)

  print(results.pose_landmarks.landmark[0].x)

  #print(results.pose_landmarks.landmark)
  mpDraw.draw_landmarks(img, results.pose_landmarks, mpPose.POSE_CONNECTIONS)
  cv2.imshow("image", img)

# Exit command

  if cv2.waitKey(1) == ord("q"):
    cap.release(0)
    cv2.destroyAllWindows()
    break

this line:

print(results.pose_landmarks.landmark[0].x)

works if the landmark comes from a photo, but when it comes from a video, it brings up the subscriptable error.

Also, if I use

print(results.pose_landmarks)

it prints all the landmarks even if the source is a photo, or the webcam. Why is it not subscriptable if the source is webcam video, but if is a photo, it is subcriptable? Thanks.

python

mediapipe

0 Answers

Your Answer

Accepted video resources