OpenCV例子四:摄像头实时人脸检测
来源:互联网 发布:大数据 普惠金融 论文 编辑:程序博客网 时间:2024/06/06 19:26
#include "stdafx.h"#include <iostream>#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O#include "opencv2/objdetect/objdetect.hpp"//人脸识别的接口using namespace cv;//必须加入,否则无法检找到OPENCV的各个函数using namespace std;string face_cascade_name = "haarcascade_frontalface_alt2.xml";CascadeClassifier face_cascade;string window_name = "人脸识别";void detectAndDisplay(Mat frame){std::vector<Rect> faces;Mat frame_gray;cvtColor( frame, frame_gray, CV_BGR2GRAY );equalizeHist( frame_gray, frame_gray );face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );for( int i = 0; i < faces.size(); i++ ){Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );}imshow(window_name, frame);}int _tmain(int argc, _TCHAR* argv[]){VideoCapture cap(0); // open the default cameraif (!cap.isOpened()) // check if we succeededreturn -1;Mat edges;//namedWindow("edges", 1);if (!face_cascade.load(face_cascade_name)){printf("[error] 无法加载级联分类器文件!\n");return -1;}int nTick = 0;for (;;){if (!cap.isOpened()){//等等摄像头打开continue;}Mat frame;nTick = getTickCount();cap >> frame; // get a new frame from cameraif (frame.data == NULL){//等到捕获到数据continue;}cvtColor(frame, edges, CV_BGR2BGRA);detectAndDisplay(edges);if (waitKey(30) >= 0) break;}return 0;}
其中XML文件在data\haarcascades目录下。该目录下有很多脚本可以使用。比如眼睛检测、身体检测等等。
注意,将该文件拷贝到程序运行目录下。另外该程序没有进行优化,会暂用很高的CPU。使用前请注意。
来自:http://blog.csdn.net/lan120576664
0 0
- OpenCV例子四:摄像头实时人脸检测
- opencv实现摄像头实时人脸检测
- OpenCV+vs2008+摄像头来实时的识别人脸(不是检测)
- opencv从摄像头读取视频并实时进行人脸检测代码
- 使用OpenCV Android SDK从摄像头帧实时检测人脸
- OpenCV+VideoInput 捕捉摄像头+人脸检测
- OPENCV人脸检测例子
- OpenCV实现读取摄像头做实时边缘检测
- python 调用摄像头,基于opencv 的人脸检测实现
- 用摄像头进行人脸和人眼实时检测的优化 算法
- 实时人脸检测
- 基于OpenCV读取摄像头进行人脸检测和人脸识别
- 基于OpenCV读取摄像头进行人脸检测和人脸识别
- 基于OpenCV读取摄像头进行人脸检测和人脸识别
- 基于OpenCV读取摄像头进行人脸检测和人脸识别
- 基于OpenCV读取摄像头进行人脸检测和人脸识别
- 关于Python+Opencv实现人脸检测的实验笔记(调用摄像头篇)
- 自学笔记:用python和opencv进行摄像头的人脸检测
- Annotation简介
- 清华大学计算机考研的相关信息,
- 蓝桥杯算法训练——最大最小公倍数(贪心)
- registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later
- ubuntu下gedit中文乱码问题
- OpenCV例子四:摄像头实时人脸检测
- 动态改变ActionBar中Menu
- TCP/IP详解笔记(6)
- POJ2752Seek the Name, Seek the Fame(KMP)
- allegro学习--区域约束
- Spring MVC 容器中设置Bean属性值 为NULL
- tomcat部署war,启动访问不到工程,需要启动两次(<Context path=""..../>)
- 第一次写博客
- 为NGSOS智能操作系统设计编程语言