-
Notifications
You must be signed in to change notification settings - Fork 45
/
FaceDetector.cpp
38 lines (30 loc) · 1.09 KB
/
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
/*
* File: FaceDetector.cpp
* Author: Eyal Arubas <EyalArubas at gmail>
*/
#include <vector>
#include "FaceDetector.h"
FaceDetector::FaceDetector(
const string &cascadePath,
double scaleFactor,
int minNeighbors,
double minSizeRatio,
double maxSizeRatio):
_scaleFactor(scaleFactor), _minNeighbors(minNeighbors), _minSizeRatio(minSizeRatio), _maxSizeRatio(maxSizeRatio){
_cascade.load(cascadePath);
}
FaceDetector::~FaceDetector() {}
void FaceDetector::findFacesInImage(const Mat &img, vector<Rect> &res) {
Mat tmp;
int width = img.size().width,
height = img.size().height;
Size minScaleSize = Size(_minSizeRatio * width, _minSizeRatio * height),
maxScaleSize = Size(_maxSizeRatio * width, _maxSizeRatio * height);
//convert the image to grayscale and normalize histogram:
cvtColor(img, tmp, CV_BGR2GRAY);
equalizeHist(tmp, tmp);
//clear the vector:
res.clear();
//detect faces:
_cascade.detectMultiScale(tmp, res, _scaleFactor, _minNeighbors, 0, minScaleSize, maxScaleSize);
}