-4

i write a script for search a hand and draw it on screen, but i have an error

AttributeError: 'numpy.ndarray' object has no attribute 'multi_hand_landmarks'

idk how to solve it. FULL CODE

import cv2
import mediapipe as mp

cap = cv2.VideoCapture(2) 
hands = mp.solutions.hands
draw = mp.solutions.drawing_utils 

while True:
    #Закрытие окна
    if cv2.waitKey(1) & 0xFF == 27:
        break

    success, image = cap.read() 
    image = cv2.flip(image, 1) 
    results =image
    for handLms in results.multi_hand_landmarks:
        for id, lm in enumerate(handLms.landmarks):
             h, w, c = image.shape
             cx, cy = int(lm.x * w), int(lm.y * h)

        draw.draw_landmarks(image, handLms, mp.solutions.hands.HAND_CONNECTIONS)

    cv2.imshow("Hand", image) 

I search in ALL sites, but i dont have a solve. Thanks.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • What class of object is supposed to have this attribute, `multi_hand_landmarks`? That isn't a familiar attribute. It certainly isn't something than an ordinary numpy array has. Is `results` supposed to an array? – hpaulj May 28 '23 at 19:15
  • 2
    Did you write any of this code yourself? Or is it just copied from a web site or tutorial without understanding what is happening? – hpaulj May 28 '23 at 19:15
  • A search won't give an exact match because no one is making exactly the same mistake. But lot of people get an `AttribteError`. And the explanation is usually simple - wrong kind of object. `result` probably shouldn't be an array. It should be something a 'image', – hpaulj May 28 '23 at 22:22
  • Example: https://stackoverflow.com/questions/76325975/how-to-make-the-hand-detection-of-mediapipe-work-on-hand-with-gloves – Markus May 28 '23 at 22:26
  • 1
    you need to follow the `mediapipe` documentation more carefully! – hpaulj May 28 '23 at 23:10

1 Answers1

0

I highly recommend you to upgrade mediapipe to the latest version 0.10.0. And then follow the documentation here: https://developers.google.com/mediapipe/solutions/vision/hand_landmarker/python

As I can see from your code, you are not calling any function to detect the hand landmarks, instead you just assigned results to image (which is a np.array) results = image.

user2586955
  • 309
  • 1
  • 5