Я хочу управлять курсором мыши, отслеживая единичное лицо, но не могу стабильно определить лицо, оно просто приходит и уходит, ps: измените путь калибровки
import cv2
from pynput.mouse import Button,Controller
cam = cv2.VideoCapture(0)
ms = Controller()
fd = cv2.CascadeClassifier(r'C:\Users\naray\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\cv2\data\haarcascade_frontalface_alt.xml')
while True:
r,i = cam.read()
j = cv2.cvtColor(i,cv2.COLOR_BGR2GRAY)
face = fd.detectMultiScale(j,1.5,2)
print('number of faces are ',len(face))
if(len(face)==1):
for (x,y,w,h) in face:
cv2.rectangle(i,(x,y),(x+w,y+h),(0,0,255),3)
ms.position = (x,y)
cv2.imshow('image',i)
k = cv2.waitKey(6)
if(k == ord('q')):
cv2.destroyAllWindows()
break