首先,用OpenCV实现对于人脸的捕获我们需要知道电脑摄像头在OpenCV中的代码数值,一般来说,摄像头的读取数值为0,需要用到VideoCapture()这个函数。另外,在OpenCV中,自带了面部识别的分类器。用到的函数代码如下:
String facefile = "D:\\OpenCV\\opencv\\build\\etc\\haarcascades\\haarcascade_frontalface_alt.xml";
另外,值得注意的是,在读取摄像头这个操作中,灰度值、帧率以及waitKey时延是很重要的三个东西,它关系到你的视频能否有一个好的观看效果。
下面是源代码:
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <opencv2/highgui/highgui_c.h>
using namespace std;
using namespace cv;
//人脸识别
void faceTest()
{
String facefile = "D:\\OpenCV\\opencv\\build\\etc\\haarcascades\\haarcascade_frontalface_alt.xml";
//脸部识别分类器
Casc