1

I am trying out opencv and handtracking for the first time. I am following step by step code from the official website of "Mediapipe". But whenever i try to write "results.multi_hand_landmarks", PyCharm gives an error saying Unresolved Attribute Reference "multi_hand_landmarks" for class "NamedTuple"

Can you please help me out?

Screenshot of the Code

Hassan Shahzad
  • 455
  • 6
  • 14

1 Answers1

0
import mediapipe
import cv2
import null as null

drawingModule = mediapipe.solutions.drawing_utils
handsModule = mediapipe.solutions.hands

capture = cv2.VideoCapture(0)

with handsModule.Hands(static_image_mode=False, min_detection_confidence=0.7, min_tracking_confidence=0.7,max_num_hands=2) as hands:
        while (True):
            ret, frame = capture.read()
            results = hands.process(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
            if results.multi_hand_landmarks:
                for handLandmarks in results.multi_hand_landmarks:
                    drawingModule.draw_landmarks(frame, handLandmarks, handsModule.HAND_CONNECTIONS)
            cv2.imshow('Test hand', frame)
            if cv2.waitKey(1) == 27:
                break
cv2.destroyAllWindows()
capture.release() here

This code will also show the same error when hovering over the same line as yours but the code runs. Possibly a bug with PyCharm and the Mediapipe library.

In the source code it is there :

outputs=['multi_hand_landmarks', 'multi_handedness'])

https://github.com/google/mediapipe/blob/710fb3de58dc10b7bc75f9cb758300c9016a5e4f/mediapipe/python/solutions/hands.py#L125

jeranio
  • 53
  • 8