-
Notifications
You must be signed in to change notification settings - Fork 71
/
FeatureDetector.cpp
33 lines (29 loc) · 1.05 KB
/
FeatureDetector.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
#include "FeatureDetector.h"
FeatureDetector::FeatureDetector(CvSize eyesize):
eyesize(eyesize),
sumimage(cvCreateImage(eyesize, IPL_DEPTH_32F, 1)),
sum2image(cvCreateImage(eyesize, IPL_DEPTH_32F, 1)),
temp(cvCreateImage(eyesize, IPL_DEPTH_32F, 1)),
samples(0)
{
cvZero(sum2image.get());
cvZero(sumimage.get());
}
void FeatureDetector::addSample(const IplImage *source) {
cvConvertScale(source, temp.get());
cvAcc(temp.get(), sumimage.get());
cvSquareAcc(temp.get(), sum2image.get());
samples++;
}
shared_ptr<IplImage> FeatureDetector::getMean() {
shared_ptr<IplImage> mean(createImage(eyesize, IPL_DEPTH_32F, 1));
cvConvertScale(sumimage.get(), mean.get(), 1.0 / samples);
return mean;
}
shared_ptr<IplImage> FeatureDetector::getVariance() {
shared_ptr<IplImage> variance(createImage(eyesize, IPL_DEPTH_32F, 1));
cvMul(sumimage.get(), sumimage.get(), temp.get(), -1.0/samples);
cvAdd(temp.get(), sum2image.get(), temp.get());
cvScale(temp.get(), variance.get(), 1.0/samples);
return variance;
}