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以及我的眼睛在看哪里来移动我的鼠标
1条答案
按热度按时间ef1yzkbh1#
enumerate()
是一个Python内置函数,它返回一个元组序列。代替
您应该使用
或
index
是子列表/切片的索引,因此您将获得索引0,1,2,3