#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
String facefile = "D:/vs/opencv/build/etc/haarcascades/haarcascade_frontalface_alt.xml";
String lefteyefile = "D:/vs/opencv/build/etc/haarcascades/haarcascade_eye.xml";
String righteyefile = "D:/vs/opencv/build/etc/haarcascades/haarcascade_eye.xml";
CascadeClassifier face_detector;
CascadeClassifier leftyeye_detector;
CascadeClassifier righteye_detector;
Rect leftEye, rightEye;
void trackEye(Mat& im, Mat& tpl, Rect& rect) {
Mat result;
int result_cols = im.cols - tpl.cols + 1;
int result_rows = im.rows - tpl.rows + 1;
// 模板匹配
result.create(result_rows, result_cols, CV_32FC1);
matchTemplate(im, tpl, result, TM_CCORR_NORMED);
// 寻找位置
double minval, maxval;
Point minloc, maxloc;
minMaxLoc(result, &minval, &maxval, &minloc, &maxloc);
if (maxval > 0.75) {
rect.x = rect.x + maxloc.x;
rect.y = rect.y + maxloc.y;
}
else {
rect.x = rect.y = rect.width = rect.height = 0;
}
}
int main(int argc, char
2021-08-28人脸检测与眼睛跟踪
最新推荐文章于 2024-08-29 10:26:23 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)