2010-05-11 19:44:00 +02:00
|
|
|
#ifndef _OPENCV_LBPFEATURES_H_
|
|
|
|
#define _OPENCV_LBPFEATURES_H_
|
|
|
|
|
|
|
|
#include "traincascade_features.h"
|
|
|
|
|
|
|
|
#define LBPF_NAME "lbpFeatureParams"
|
|
|
|
struct CvLBPFeatureParams : CvFeatureParams
|
|
|
|
{
|
|
|
|
CvLBPFeatureParams();
|
2012-10-17 09:12:04 +02:00
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CvLBPEvaluator : public CvFeatureEvaluator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~CvLBPEvaluator() {}
|
|
|
|
virtual void init(const CvFeatureParams *_featureParams,
|
2013-11-16 16:56:08 +01:00
|
|
|
int _maxSampleCount, cv::Size _winSize );
|
|
|
|
virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx);
|
2010-05-11 19:44:00 +02:00
|
|
|
virtual float operator()(int featureIdx, int sampleIdx) const
|
|
|
|
{ return (float)features[featureIdx].calc( sum, sampleIdx); }
|
2013-11-16 16:56:08 +01:00
|
|
|
virtual void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const;
|
2010-05-11 19:44:00 +02:00
|
|
|
protected:
|
|
|
|
virtual void generateFeatures();
|
|
|
|
|
|
|
|
class Feature
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Feature();
|
2012-10-17 09:12:04 +02:00
|
|
|
Feature( int offset, int x, int y, int _block_w, int _block_h );
|
2013-11-16 16:56:08 +01:00
|
|
|
uchar calc( const cv::Mat& _sum, size_t y ) const;
|
|
|
|
void write( cv::FileStorage &fs ) const;
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2013-11-16 16:56:08 +01:00
|
|
|
cv::Rect rect;
|
2010-05-11 19:44:00 +02:00
|
|
|
int p[16];
|
|
|
|
};
|
2013-02-24 17:14:01 +01:00
|
|
|
std::vector<Feature> features;
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2013-11-16 16:56:08 +01:00
|
|
|
cv::Mat sum;
|
2010-05-11 19:44:00 +02:00
|
|
|
};
|
|
|
|
|
2013-11-16 16:56:08 +01:00
|
|
|
inline uchar CvLBPEvaluator::Feature::calc(const cv::Mat &_sum, size_t y) const
|
2010-05-11 19:44:00 +02:00
|
|
|
{
|
2012-08-28 16:15:14 +02:00
|
|
|
const int* psum = _sum.ptr<int>((int)y);
|
|
|
|
int cval = psum[p[5]] - psum[p[6]] - psum[p[9]] + psum[p[10]];
|
|
|
|
|
|
|
|
return (uchar)((psum[p[0]] - psum[p[1]] - psum[p[4]] + psum[p[5]] >= cval ? 128 : 0) | // 0
|
|
|
|
(psum[p[1]] - psum[p[2]] - psum[p[5]] + psum[p[6]] >= cval ? 64 : 0) | // 1
|
|
|
|
(psum[p[2]] - psum[p[3]] - psum[p[6]] + psum[p[7]] >= cval ? 32 : 0) | // 2
|
|
|
|
(psum[p[6]] - psum[p[7]] - psum[p[10]] + psum[p[11]] >= cval ? 16 : 0) | // 5
|
|
|
|
(psum[p[10]] - psum[p[11]] - psum[p[14]] + psum[p[15]] >= cval ? 8 : 0) | // 8
|
|
|
|
(psum[p[9]] - psum[p[10]] - psum[p[13]] + psum[p[14]] >= cval ? 4 : 0) | // 7
|
|
|
|
(psum[p[8]] - psum[p[9]] - psum[p[12]] + psum[p[13]] >= cval ? 2 : 0) | // 6
|
|
|
|
(psum[p[4]] - psum[p[5]] - psum[p[8]] + psum[p[9]] >= cval ? 1 : 0)); // 3
|
2010-05-11 19:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|