-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFaceDetector.cpp
More file actions
35 lines (28 loc) · 1.05 KB
/
Copy pathFaceDetector.cpp
File metadata and controls
35 lines (28 loc) · 1.05 KB
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
#include "FaceDetector.h"
#include <cassert>
using StalkR::FaceDetector;
FaceDetector::FaceDetector(const std::string &classifierPath) throw(std::invalid_argument)
: m_cascade(new cv::CascadeClassifier(classifierPath))
{
if (m_cascade->empty())
throw std::invalid_argument("Couldn't load classifier from: " + classifierPath);
}
void FaceDetector::recognize(const std::string &inputPath) throw(std::runtime_error)
{
m_faces.clear();
m_image = cv::imread(inputPath, CV_LOAD_IMAGE_GRAYSCALE);
if (!m_image.data)
throw std::invalid_argument("Couldn't load image from: " + inputPath);
static const double scaleFactor = 1.1;
static const int minNeighbours = 6;
m_cascade->detectMultiScale(m_image, m_faces, scaleFactor, minNeighbours, 0);
}
void FaceDetector::outputFace(const std::string &outputPath) throw(std::runtime_error)
{
assert(facesRemaining());
cv::Mat face = m_image(m_faces.back());
m_faces.pop_back();
cv::Mat resized;
cv::resize(face, resized, cv::Size(256, 256));
cv::imwrite(outputPath, resized);
}