-
Notifications
You must be signed in to change notification settings - Fork 0
/
Algorithm_FaceDetector.cpp
43 lines (30 loc) · 1.21 KB
/
Algorithm_FaceDetector.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "Algorithm_FaceDetector.h"
#include <opencv2/objdetect/objdetect.hpp>
#include <string>
#include <ostream>
FaceDetector::FaceDetector(){
this->_classifier.load("xml/haarcascade_frontalface_default.xml");
}
//void recognize(const cv::Mat &in);
void FaceDetector::process(const cv::Mat &in, cv::Mat &out) {
// Create a new image based on the input image
out = in.clone();
std::vector<cv::Rect> faces;
// There can be more than one face in an image.
// So create a growable sequence of faces.
// Detect the objects and store them in the sequence
this->_classifier.detectMultiScale(out, faces, 1.2, 3, CV_HAAR_DO_CANNY_PRUNING, cv::Size(25, 25));
int nbFaces=0;
// Loop the number of faces found.
for( size_t i = 0; i < faces.size(); ++i ) {
// Draw the rectangle in the input image
cv::rectangle( out, faces.at(i), cv::Scalar(255,0,0), 3, 8, 0);
}
cv::Point point;
point.x=20;
point.y=20;
std::string faces_ = static_cast<std::ostringstream*>( &(std::ostringstream() << nbFaces) )->str();
//cv::Mat test;
cv::putText(out, "Number of Faces : "+faces_, point, cv::FONT_HERSHEY_COMPLEX_SMALL, 0.8, cv::Scalar(255,0,0), 1, CV_AA);
return;
}