“numpy.ndarray”对象没有属性“multi_hand_landmarks”

6vl6ewon  于 2023-06-23  发布在  其他
关注(0)|答案(1)|浏览(189)

我写了一个搜索手的脚本,并把它画在屏幕上,但我有一个错误

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

idk如何解决它。完整代码

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)

我在所有的网站搜索,但我没有一个解决方案。谢谢

aamkag61

aamkag611#

我强烈建议您将mediapipe升级到最新版本0.10.0。然后按照这里的文档:https://developers.google.com/mediapipe/solutions/vision/hand_landmarker/python
正如我从代码中看到的,您没有调用任何函数来检测手部标志,而是将结果分配给image(这是一个np.数组)results = image。

相关问题