python 运行时它告诉我'tuple'对象没有属性'x'下面是我的代码

t98cgbkg  于 2023-02-07  发布在  Python
关注(0)|答案(1)|浏览(166)
import cv2
import mediapipe as mp
import pyautogui as py
cam = cv2.VideoCapture(0)

face_mesh = mp.solutions.face_mesh.FaceMesh(refine_landmarks=True)
while True:
    _, frame = cam.read()
    frame = cv2.flip(frame, 1)
    frameRGB = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
    output = face_mesh.process(frameRGB)
    face_landmark = output.multi_face_landmarks
    frame_w, frame_h, _ = frame.shape
    if face_landmark:
        ***landmarks = face_landmark[0].landmark
        for landmark in enumerate(landmarks[474:478]):
            x = int(landmark.x * frame_w)
            y = int(landmark.y * frame_h)***
            cv2.circle(frame, (x, y), 3, (0, 255, 0))
            if id == 1:
                py.moveTo(x, y)

            print(x, y)
    cv2.imshow('Lazy mouse', frame)
    cv2.waitKey(1)

它应该让我的眼睛打开一个屏幕,把点放在我的眼睛周围,然后使用x和y以及我的眼睛在看哪里来移动我的鼠标

ef1yzkbh

ef1yzkbh1#

enumerate()是一个Python内置函数,它返回一个元组序列。
代替

for landmark in enumerate(landmarks[474:478]):  # wrong

您应该使用

for landmark in landmarks[474:478]:

for (index, landmark) in enumerate(landmarks[474:478]):

index是子列表/切片的索引,因此您将获得索引0,1,2,3

相关问题