我第一次尝试opencv和handtracking。我正在按照“Mediapipe”官方网站上的逐步代码进行操作。但是每当我尝试编写“results.multi_hand_landmarks”时,PyCharm 都会给出错误提示Unresolved Attribute Reference "multi_hand_landmarks" for class "NamedTuple"
你能帮帮我吗?
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
当将鼠标悬停在与您相同的行上但代码运行时,此代码也会显示相同的错误。可能是 PyCharm 和 Mediapipe 库的错误。
在源代码中它在那里:
输出=['multi_hand_landmarks', 'multi_handedness'])