Fixed compilation errors: removed using namespace from hpp file. This led to pulling...
[profile/ivi/opencv.git] / apps / traincascade / lbpfeatures.cpp
1 #include "opencv2/core/core.hpp"
2 #include "opencv2/core/internal.hpp"
3
4 #include "lbpfeatures.h"
5 #include "cascadeclassifier.h"
6
7 using namespace cv;
8
9 CvLBPFeatureParams::CvLBPFeatureParams()
10 {
11     maxCatCount = 256;
12     name = LBPF_NAME;
13 }
14
15 void CvLBPEvaluator::init(const CvFeatureParams *_featureParams, int _maxSampleCount, Size _winSize)
16 {
17     CV_Assert( _maxSampleCount > 0);
18     sum.create((int)_maxSampleCount, (_winSize.width + 1) * (_winSize.height + 1), CV_32SC1);
19     CvFeatureEvaluator::init( _featureParams, _maxSampleCount, _winSize );
20 }
21
22 void CvLBPEvaluator::setImage(const Mat &img, uchar clsLabel, int idx)
23 {
24     CV_DbgAssert( !sum.empty() );
25     CvFeatureEvaluator::setImage( img, clsLabel, idx );
26     Mat innSum(winSize.height + 1, winSize.width + 1, sum.type(), sum.ptr<int>((int)idx));
27     integral( img, innSum );
28 }
29
30 void CvLBPEvaluator::writeFeatures( FileStorage &fs, const Mat& featureMap ) const
31 {
32     _writeFeatures( features, fs, featureMap );
33 }
34
35 void CvLBPEvaluator::generateFeatures()
36 {
37     int offset = winSize.width + 1;
38     for( int x = 0; x < winSize.width; x++ )
39         for( int y = 0; y < winSize.height; y++ )
40             for( int w = 1; w <= winSize.width / 3; w++ )
41                 for( int h = 1; h <= winSize.height / 3; h++ )
42                     if ( (x+3*w <= winSize.width) && (y+3*h <= winSize.height) )
43                         features.push_back( Feature(offset, x, y, w, h ) );
44     numFeatures = (int)features.size();
45 }
46
47 CvLBPEvaluator::Feature::Feature()
48 {
49     rect = cvRect(0, 0, 0, 0);
50 }
51
52 CvLBPEvaluator::Feature::Feature( int offset, int x, int y, int _blockWidth, int _blockHeight )
53 {
54     Rect tr = rect = cvRect(x, y, _blockWidth, _blockHeight);
55     CV_SUM_OFFSETS( p[0], p[1], p[4], p[5], tr, offset )
56     tr.x += 2*rect.width;
57     CV_SUM_OFFSETS( p[2], p[3], p[6], p[7], tr, offset )
58     tr.y +=2*rect.height;
59     CV_SUM_OFFSETS( p[10], p[11], p[14], p[15], tr, offset )
60     tr.x -= 2*rect.width;
61     CV_SUM_OFFSETS( p[8], p[9], p[12], p[13], tr, offset )
62 }
63
64 void CvLBPEvaluator::Feature::write(FileStorage &fs) const
65 {
66     fs << CC_RECT << "[:" << rect.x << rect.y << rect.width << rect.height << "]";
67 }