haar detection demo code
来源:互联网 发布:北京房山网络职业学院 编辑:程序博客网 时间:2024/05/18 13:06
#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 = "C:\\Users\\admin\\Desktop\\opencv_fdace\\face_detect\\face_detect\\haarcascade_frontalface_alt.xml";
CascadeClassifier face_cascade;
string window_name = "real time 人脸检测";
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 main(int argc, _TCHAR* argv[])
{
VideoCapture cap(0); // open the default camera
if (!cap.isOpened()) // check if we succeeded
return -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 camera
if (frame.data == NULL)
{//等到捕获到数据
continue;
}
cvtColor(frame, edges, CV_BGR2BGRA);
detectAndDisplay(edges);
if (waitKey(30) >= 0) break;
}
return 0;
}
#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 = "C:\\Users\\admin\\Desktop\\opencv_fdace\\face_detect\\face_detect\\haarcascade_frontalface_alt.xml";
CascadeClassifier face_cascade;
string window_name = "real time 人脸检测";
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 main(int argc, _TCHAR* argv[])
{
VideoCapture cap(0); // open the default camera
if (!cap.isOpened()) // check if we succeeded
return -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 camera
if (frame.data == NULL)
{//等到捕获到数据
continue;
}
cvtColor(frame, edges, CV_BGR2BGRA);
detectAndDisplay(edges);
if (waitKey(30) >= 0) break;
}
return 0;
}
0 0
- haar detection demo code
- Face Detection using Haar Cascades
- 【opencv】Face Detection using Haar Cascades
- tensorflow object detection demo
- Face Detection Matlab Code
- Code for Anomaly Detection
- shadow detection in opencv code
- 【计算机视觉】Opencv中的Face Detection using Haar Cascades
- Haar
- haar
- ios emoji demo code
- 09-17 demo code
- AdMob demo code.
- Google Glog Demo Code.
- bootstrap-demo-source-code
- golang redis demo code
- [code].检测内存泄漏 memory detection.
- Automated leak detection in managed code
- hashset,linkhashset,treeset区别
- Mantis邮件终于能发送啦!
- LuaJavaBridge - Lua 与 Java 互操作的简单解决方案
- 使用WebView实现离线阅读
- 华为机试---聊天
- haar detection demo code
- SMA、SMB、SMC封装的二极管尺寸区分
- [转]使 Windows 下的 Qt 应用程序获得 Administrator 权限
- 电脑桌面图标或者文件左下角出现蓝色问号解决办法
- static作用
- JS-2---表达式和运算符
- bootstrap table 插件 从服务器请求数据 分页
- Andoird 自定义ViewGroup
- iOS开发中常见崩溃原因汇总,你遇到了吗?