. Cascade Classifier
#include “opencv2/objdetect.hpp”
#include “opencv2/highgui.hpp”
#include “opencv2/imgproc.hpp”
#include “opencv2/videoio.hpp”
#include
using namespace std;
using namespace cv;
void detectAndDisplay( Mat frame );
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
int main( int argc, const char** argv )
{
String face_cascade_name = samples::findFile("/home/chang/projects/opencv_GPU_example/haarcascade_frontalcatface.xml");
String eyes_cascade_name = samples::findFile("/home/chang/projects/opencv_GPU_example/haarcascade_eye_tree_eyeglasses.xml");
//-- 1. Load the cascades
if( !face_cascade.load(face_cascade_name))
{
cout << “–(!)Error loading face cascade\n”;
return -1;
}
if( !eyes_cascade.load(eyes_cascade_name))
{
cout << “–(!)Error loading eyes cascade\n”;
return -1;
}
int camera_device = 0;
VideoCapture capture;
//-- 2. Read the video stream
capture.open( camera_device );
if ( ! capture.isOpened() )
{
cout << “–(!)Error opening video capture\n”;
return -1;
}
Mat frame;
while ( capture.read(frame) )
{
if( frame.empty() )
{
cout << “–(!) No captured frame – Break!\n”;
break;
}
//-- 3. Apply the classifier to the frame
detectAndDisplay( frame );
if( waitKey(10) == 27 )
{
break; // escape
}
}
return 0;
}
void detectAndDisplay( Mat frame )
{
Mat frame_gray;
cvtColor( frame, frame_gray, COLOR_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );
//-- Detect faces
std::vector
face_cascade.detectMultiScale( frame_gray, faces );
for ( size_t i = 0; i < faces.size(); i++ )
{
Point center( faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2 );
ellipse( frame, center, Size( faces[i].width/2, faces[i].height/2 ), 0, 0, 360, Scalar( 255, 0, 255 ), 4 );
Mat faceROI = frame_gray( faces[i] );
//-- In each face, detect eyes
std::vector
eyes_cascade.detectMultiScale( faceROI, eyes );
for ( size_t j = 0; j < eyes.size(); j++ )
{
Point eye_center( faces[i].x + eyes[j].x + eyes[j].width/2, faces[i].y + eyes[j].y + eyes[j].height/2 );
int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
circle( frame, eye_center, radius, Scalar( 255, 0, 0 ), 4 );
}
}
//-- Show what you got
imshow( “Capture - Face detection”, frame );
}
上一篇: 动态读取nacos配置工具类
下一篇: 由进程名字获取进程 ID
推荐阅读
-
drop table cascade
-
在DROP TABLE时,RESTRICT与CASCADE的区别?
-
. Cascade Classifier
-
sql server CASCADE 添加级联删除和级联更新(详细版)
-
hibernate cascade
-
Oracle 删除用户drop user cascade报错解决方案
-
Oracle 在 Drop 表时的 Cascade Constraints
-
Cascade
-
集成学习voting Classifier在sklearn中的实现(投票机制)
-
MySql 外键约束 之CASCADE、SET NULL、RESTRICT、空等类型分析和_MySQL