在这段代码中,我使用的是Python 2.7.13,OpenCV 2.4.13和PyAutoGUI 0.9.36.目标是根据面部运动移动光标,但光标移动被反转.例如,如果我的脸向右移动,则光标向左移动,如果我的脸向左移动,则光标向右移动.此外,我希望光标在我的PC的整个屏幕中向右,向左,向上和向下移动,其大小为x = 1920,y = 1080.
该计划的目的是表明有可能获得一种获得更多独立性和获取途径的新方法,以便患有四肢瘫痪的人能够进行简单的活动,这些活动是数百万人的常规活动的一部分,例如转动打开和关闭灯,打开和关闭电视.
import cv2
import pyautogui
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
video_capture = cv2.VideoCapture(0)
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.3,
minNeighbors=5,
minSize=(80, 80),
flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)
#print 'faces: ', faces
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 0, 255), 3)
#width, height = pyautogui.size()
#cursorx, cursory = pyautogui.position()
#posx = width …Run Code Online (Sandbox Code Playgroud)