本科毕设项目丨眼睛控制鼠标移动

本文选用Visual Studio 2019开发工具,选择C++编程语言,同时结合了基于Qt的应用程序架构与OpenCV计算机视觉库进行联合开发。

包含“摄像头的打开”,“人脸检测” ,“人眼检测”,“瞳孔检测”,“眼控鼠标”等功能

摄像头的打开 采用了 opencv中 video capture函数

VideoCapture capture(0);

人脸检测采用的是基于opencvdnn模块中的TensorFlow模型

std::string root_dir = "D:/Path/opencv/sources/samples/dnn/face_detector/";
dnn::Net net = dnn::readNetFromTensorflow(root_dir + "opencv_face_detector_uint8.pb", root_dir + "opencv_face_detector.pbtxt");
 Mat blob = dnn::blobFromImage(frame, 1.0, Size(300, 300), Scalar(104, 177, 123), false, false);
net.setInput(blob);// NCHW
Mat probs = net.forward(); // 
Mat detectionMat(probs.size[2], probs.size[3], CV_32F, probs.ptr<float>());
for (int i = 0; i < detectionMat.rows; i++) {
float confidence = detectionMat.at<float>(i, 2);
if (confidence > 0.5) {
int x1 = static_cast<int>(detectionMat.at<float>(i, 3) * debugImage.cols);
int y1 = static_cast<int>(detectionMat.at<float>(i, 4) * debugImage.rows);
int x2 = static_cast<int>(detectionMat.at<float>(i, 5) * debugImage.cols);
int y2 = static_cast<int>(detectionMat.at<float>(i, 6) * debugImage.rows);
Rect face(x1, y1, x2 - x1, y2 - y1);
rectangle(debugImage,face, Scalar(0, 0, 255), 2, 8, 0);       

人眼检测采用的是 三庭五眼比例法 进行检测

// Size constants 尺寸常数    
const int kEyePercentTop = 25;
const int kEyePercentSide = 13;
const int kEyePercentHeight = 30;
const int kEyePercentWidth = 35;

瞳孔检测采用的是 图像梯度算法 进行检测

f (kSmoothFaceImage) {
    double sigma = kSmoothFaceFactor * face.width;  //之前的定义 Ksmoothfacefactor为0.005
    GaussianBlur(faceROI, faceROI, cv::Size(0, 0), sigma); //高斯模糊处理
}
//-- Find eye regions and draw them  找到眼睛区域 并绘制他们

int eye_region_width = face.width * (kEyePercentWidth / 100.0);//35  眼部相对于检测脸部的宽
int eye_region_height = face.width * (kEyePercentHeight / 100.0);//30 眼部相对于检测脸部的高度

// eye_region_y  
int eye_region_top = face.height * (kEyePercentTop / 100.0);//25 左右眼ROI图像左上角像素点位置:yl yr

cv::Rect leftEyeRegion(face.width * (kEyePercentSide / 100.0),  //13
    eye_region_top,
    eye_region_width,
    eye_region_height);

cv::Rect rightEyeRegion(face.width - eye_region_width - face.width * (kEyePercentSide / 100.0),
    eye_region_top,
    eye_region_width,
    eye_region_height);

rectangle(debugFace, rightEyeRegion, Scalar(0, 0, 255));//red 红色框柱右眼
rectangle(debugFace, leftEyeRegion, Scalar(0, 0, 255));//red 红色框住左眼

 //-- Find Eye Centers  找到眼睛中心
cv::Point leftPupil = findEyeCenter(faceROI, leftEyeRegion, "Left Eye");
cv::Point rightPupil = findEyeCenter(faceROI, rightEyeRegion, "Right Eye");
 

眼控鼠标采用的是SetCurous函数进行实时控制

SetCursorPos(Q, W);

B站文章链接:本科毕设项目丨眼睛控制鼠标移动 - 哔哩哔哩 (bilibili.com)icon-default.png?t=M4ADhttps://www.bilibili.com/read/cv17062745

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值