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

本科毕设项目丨眼睛控制鼠标移动,第1张

本文选用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());
for (int i = 0; i < detectionMat.rows; i++) {
float confidence = detectionMat.at(i, 2);
if (confidence > 0.5) {
int x1 = static_cast(detectionMat.at(i, 3) * debugImage.cols);
int y1 = static_cast(detectionMat.at(i, 4) * debugImage.rows);
int x2 = static_cast(detectionMat.at(i, 5) * debugImage.cols);
int y2 = static_cast(detectionMat.at(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);

原码可私信博主 

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1352521.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-14
下一篇 2022-06-14

发表评论

登录后才能评论

评论列表(0条)

保存