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

编程入门 行业动态 更新时间:2024-10-08 01:32:41

本科毕设项目丨眼睛控制<a href=https://www.elefans.com/category/jswz/34/1769042.html style=鼠标移动"/>

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

本文选用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)

更多推荐

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

本文发布于:2024-02-14 09:55:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1762732.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:鼠标   本科   眼睛   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!