栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/975170.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号