How can I move mouse by detected face and Eye using OpenCV and Python

我是研究僧i 提交于 2019-12-08 18:45:27

If you're working in Windows environment, what you're looking for is the SetCursorPos method in the python win32api. Use:

import win32api
import cv2
import sys
...
for (ex,ey,ew,eh) in eyes:
    win32api.SetCursorPos((ex,ey))
    cv2.rectangle(roi_color,(ex,ey), (ex+ew,ey+eh), (0,255,0), 2)

This will set the cursor to the top-left vertex of the rectangle. If you wish to move the cursor to the center of the rect, use:

win32api.SetCursorPos((ex+ew/2,ey+eh/2))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!