opencv2实现人脸及人眼检测_相当稳定

  1. //opencv2检测人脸人眼的方法有很多,我试了集中,下面的程序得到的结果最准确。人可以随意动,只要摄像头可以,就没有问题。

[cpp] view
plain
copyprint?

  1. /* */
  2. #include "opencv2/objdetect/objdetect.hpp"
  3. #include "opencv2/highgui/highgui.hpp"
  4. #include "opencv2/imgproc/imgproc.hpp"
  5. #include <iostream>
  6. #include <stdio.h>
  7. #include <opencv2/core/core.hpp>
  8. using namespace std;
  9. using namespace cv;
  10. // Function Headers
  11. void detectAndDisplay( Mat frame );
  12. // Global variables
  13. String face_cascade_name = "haarcascade_frontalface_alt.xml";
  14. String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
  15. CascadeClassifier face_cascade;
  16. CascadeClassifier eyes_cascade;
  17. string window_name = "Capture - Face detection";
  18. RNG rng(12345);
  19. // @function main
  20. int main( int argc, const char** argv )
  21. {
  22. // CvCapture* capture;
  23. Mat frame;
  24. //-- 1. Load the cascades
  25. if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  26. if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  27. //-- 2. Read the video stream
  28. CvCapture* capture=cvCaptureFromCAM(0);
  29. //capture = cvCaptureFromCAM( -1 );
  30. if( capture )
  31. {
  32. while( true )
  33. {
  34. frame = cvQueryFrame( capture );
  35. //-- 3. Apply the classifier to the frame
  36. if( !frame.empty() )
  37. { detectAndDisplay( frame ); }
  38. else
  39. { printf(" --(!) No captured frame -- Break!"); break; }
  40. int c = waitKey(10);
  41. if( (char)c == ‘c‘ ) { break; }
  42. }
  43. }
  44. return 0;
  45. }
  46. // @function detectAndDisplay
  47. void detectAndDisplay( Mat frame )
  48. {
  49. std::vector<Rect> faces;
  50. Mat frame_gray;
  51. cvtColor( frame, frame_gray, CV_BGR2GRAY );
  52. equalizeHist( frame_gray, frame_gray );
  53. //-- Detect faces
  54. face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
  55. for( size_t i = 0; i < faces.size(); i++ )
  56. {
  57. Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
  58. ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 2, 8, 0 );
  59. Mat faceROI = frame_gray( faces[i] );
  60. std::vector<Rect> eyes;
  61. //-- In each face, detect eyes
  62. eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
  63. for( size_t j = 0; j < eyes.size(); j++ )
  64. {
  65. Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
  66. int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
  67. circle( frame, center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
  68. }
  69. }
  70. //-- Show what you got
  71. imshow( window_name, frame );
  72. }
时间: 2024-08-01 16:54:22

opencv2实现人脸及人眼检测_相当稳定的相关文章

opencv2实现人脸眼鼻口检测_不大稳定

#include <opencv2/core/core.hpp> #include <opencv2/highgui//highgui.hpp> #include <opencv2/objdetect/objdetect.hpp> #include <string> #include <vector> using namespace std; int main() { cv::CascadeClassifier mFaceDetector; cv

opencv实现人脸,人眼,微笑检测

1.首先实现人脸检测 1 import cv2 2 3 img = cv2.imread("people.jpg",1) #读入图像 4 #导入人脸级联分类器引擎,“.xml”文件里包含了训练出来的人脸特征 5 face_engine = cv2.CascadeClassifier(cv2.data.haarcascades+'haarcascade_frontalface_default.xml') 6 #用人脸级联分类器引擎进行人脸识别,返回的faces为人脸的坐标列表 7 #sc

图像人脸检测+人眼检测 (opencv + c++)

摘要:实现图像中人脸检测,和人眼定位.输出检测标记图像和定位坐标. 工具:vs2015 opencv3  C++ 资源:haarcascade_frontalface_alt2.xml;haarcascade_eye_tree_eyeglasses.xml 链接:https://pan.baidu.com/s/1uk8P1TF7XXCoMMd0sNDGVg 提取码:az01 实现结果: 实现过程: Detect.h 1 #pragma once 2 #include <opencv2/openc

matlab工具箱之人眼检测+meanshift跟踪算法--人眼跟踪

Viola-Jones 人眼检测算法+meanshift跟踪算法 这次的代码是对视频中的人眼部分进行检测加跟踪,检测用的是matlab自带的人眼检测工具箱 下面是matlab官网介绍这个算法的一些东西: http://cn.mathworks.com/help/vision/examples/face-detection-and-tracking-using-camshift.html?searchHighlight=Viola-Jones http://cn.mathworks.com/hel

视频序列中扣图,在扣下的区域进行人眼检测

代码功能: 1.能打开视频逐帧显示,按除ESC外任意键显示 2.鼠标在视频上滑动画矩形确定人眼检测范围 3.按ESC确认矩形范围,销毁窗口并进行人眼检测 // FindEyeInVideo.cpp : 定义控制台应用程序的入口点. //cxcore.lib cv.lib ml.lib cvaux.lib highgui.lib cvcam.lib #include "stdafx.h" #include "cv.h" #include "highgui.h

基于CNN的人脸相似度检测

人脸相似度检测主要是检测两张图片中人脸的相似度,从而判断这两张图片的对象是不是一个人. 在上一篇文章中,使用CNN提取人脸特征,然后利用提取的特征进行分类.而在人脸相似度检测的工作中,我们也可以利用卷积神经网络先提取特征,然后对提取的特征进行利用. 我们取fc7提取的4096维特征,然后对两个向量进行pairwise相似度检测,即可得到人脸相似度,然后设定一个阈值,判断是否维同一个人.

opencv2实现路线路牌检测_计算机视觉大作业2终版

main.cpp #include<stdio.h> #include <iostream> #include <vector> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include<string> #include <sstream> #include "linefinder.h" #inclu

SmileyFace——基于OpenCV的人脸人眼检测、面部识别程序

项目地址 https://github.com/guoyaohua/SmileyFace 开发环境 Visual Studio 2010 MFC + OpenCV 功能描述 静态图像人脸检测 视频人脸追踪检测 摄像头人脸检测 人脸切割显示 实时面部识别 样本自动采集 基于面部识别的程序锁 系统框图 人脸检测 人脸识别 系统截图 本程序以用户体验为中心,界面简洁.明了.易于操作.即使第一次使用该应用,也可以流利的操作. 1.主界面 2.人脸检测效果图--标准正脸 3.人脸检测效果图--人脸集 4.

opencv2实现单张图片的路线路牌检测_计算机视觉大作业2

有好多代码没有用 linefiner.h #if !defined LINEF #define LINEF #include<cmath> #include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #define PI 3.1415926 class LineFinder { private: // original image cv::Mat img; // vector conta