42
#ifndef __OPENCV_FEATURE_HPP__
43
#define __OPENCV_FEATURE_HPP__
45
#include "opencv2/core.hpp"
46
#include "opencv2/imgproc.hpp"
58
inline
namespace
tracking {
63
inline
namespace
contrib_feature {
65
#define FEATURES "features"
67
#define CC_FEATURES FEATURES
68
#define CC_FEATURE_PARAMS "featureParams"
69
#define CC_MAX_CAT_COUNT "maxCatCount"
70
#define CC_FEATURE_SIZE "featSize"
71
#define CC_NUM_FEATURES "numFeat"
72
#define CC_ISINTEGRAL "isIntegral"
73
#define CC_RECTS "rects"
74
#define CC_TILTED "tilted"
75
#define CC_RECT "rect"
77
#define LBPF_NAME "lbpFeatureParams"
78
#define HOGF_NAME "HOGFeatureParams"
79
#define HFP_NAME "haarFeatureParams"
81
#define CV_HAAR_FEATURE_MAX 3
85
#define CV_SUM_OFFSETS( p0, p1, p2, p3, rect, step ) \
87
(p0) = (rect).x + (step) * (rect).y; \
89
(p1) = (rect).x + (rect).width + (step) * (rect).y; \
91
(p2) = (rect).x + (step) * ((rect).y + (rect).height); \
93
(p3) = (rect).x + (rect).width + (step) * ((rect).y + (rect).height);
95
#define CV_TILTED_OFFSETS( p0, p1, p2, p3, rect, step ) \
97
(p0) = (rect).x + (step) * (rect).y; \
99
(p1) = (rect).x - (rect).height + (step) * ((rect).y + (rect).height);\
101
(p2) = (rect).x + (rect).width + (step) * ((rect).y + (rect).width); \
103
(p3) = (rect).x + (rect).width - (rect).height \
104
+ (step) * ((rect).y + (rect).width + (rect).height);
106
float
calcNormFactor(
const
Mat& sum,
const
Mat& sqSum );
108
template<
class
Feature>
109
void
_writeFeatures(
const
std::vector<Feature> features, FileStorage &fs,
const
Mat& featureMap )
111
fs << FEATURES <<
"[";
112
const
Mat_<int>& featureMap_ = (
const
Mat_<int>&) featureMap;
113
for
(
int
fi = 0; fi < featureMap.cols; fi++ )
114
if( featureMap_( 0, fi ) >= 0 )
117
features[fi].write( fs );
132
virtual
bool
read(
const
FileNode
&node ) = 0;
134
virtual
void
printDefaults()
const;
135
virtual
void
printAttrs()
const;
136
virtual
bool
scanAttr(
const
std::string prmName,
const
std::string val );
152
virtual
void
write(
FileStorage
&fs )
const
CV_OVERRIDE;
153
virtual
bool
read(
const
FileNode
&node ) CV_OVERRIDE;
166
virtual
void
init(
const
CvFeatureParams
*_featureParams,
int
_maxSampleCount,
Size
_winSize );
167
virtual
void
setImage(
const
Mat& img, uchar clsLabel,
int
idx );
168
virtual
void
writeFeatures(
FileStorage
&fs,
const
Mat& featureMap )
const
= 0;
169
virtual
float
operator()(
int
featureIdx,
int
sampleIdx ) = 0;
172
int
getNumFeatures()
const
176
int
getMaxCatCount()
const
178
return
featureParams->maxCatCount;
180
int
getFeatureSize()
const
182
return
featureParams->featSize;
184
const
Mat& getCls()
const
188
float
getCls(
int
si )
const
190
return
cls.
at<
float>( si, 0 );
193
virtual
void
generateFeatures() = 0;
209
virtual
void
write(
FileStorage
&fs )
const
CV_OVERRIDE;
210
virtual
bool
read(
const
FileNode
&node ) CV_OVERRIDE;
212
virtual
void
printDefaults()
const
CV_OVERRIDE;
213
virtual
void
printAttrs()
const
CV_OVERRIDE;
214
virtual
bool
scanAttr(
const
std::string prm,
const
std::string val ) CV_OVERRIDE;
229
bool
eval(
const
Mat& image,
Rect
ROI,
float* result )
const;
231
const
std::vector<float>& getWeights()
const;
232
const
std::vector<Rect>& getAreas()
const;
237
float
getInitMean()
const;
238
float
getInitSigma()
const;
243
std::vector<float> m_weights;
246
void
generateRandomFeature(
Size
imageSize );
247
float
getSum(
const
Mat& image,
Rect
imgROI )
const;
248
std::vector<Rect> m_areas;
251
float
m_scaleFactorHeight;
252
float
m_scaleFactorWidth;
253
std::vector<Rect> m_scaleAreas;
254
std::vector<float> m_scaleWeights;
258
virtual
void
init(
const
CvFeatureParams
*_featureParams,
int
_maxSampleCount,
Size
_winSize ) CV_OVERRIDE;
259
virtual
void
setImage(
const
Mat& img, uchar clsLabel = 0,
int
idx = 1 ) CV_OVERRIDE;
260
virtual
float
operator()(
int
featureIdx,
int
sampleIdx ) CV_OVERRIDE;
261
virtual
void
writeFeatures(
FileStorage
&fs, const
Mat& featureMap ) const CV_OVERRIDE;
266
return
features[idx];
268
void
setWinSize(
Size
patchSize );
269
Size
setWinSize()
const;
270
virtual
void
generateFeatures() CV_OVERRIDE;
278
virtual
void
generateFeatures(
int
numFeatures );
285
void
compute_integral( const
cv::
Mat
& img, std::vector<
cv::
Mat_<
float> > & ii_imgs )
289
split( ii_img, ii_imgs );
292
std::vector<FeatureHaar> features;
307
virtual
void
init(
const
CvFeatureParams
*_featureParams,
int
_maxSampleCount,
Size
_winSize ) CV_OVERRIDE;
308
virtual
void
setImage(
const
Mat& img, uchar clsLabel,
int
idx ) CV_OVERRIDE;
309
virtual
float
operator()(
int
varIdx,
int
sampleIdx ) CV_OVERRIDE;
310
virtual
void
writeFeatures(
FileStorage
&fs,
const
Mat& featureMap )
const
CV_OVERRIDE;
312
virtual
void
generateFeatures() CV_OVERRIDE;
313
virtual
void
integralHistogram(
const
Mat
&img, std::vector<Mat> &histogram,
Mat
&
norm,
int
nbins )
const;
318
Feature(
int
offset,
int
x,
int
y,
int
cellW,
int
cellH );
319
float
calc(
const
std::vector<Mat> &_hists,
const
Mat
&_normSum,
size_t
y,
int
featComponent )
const;
330
std::vector<Feature> features;
333
std::vector<Mat> hist;
336
inline
float
CvHOGEvaluator::operator()(
int
varIdx,
int
sampleIdx )
338
int
featureIdx = varIdx / ( N_BINS * N_CELLS );
339
int
componentIdx = varIdx % ( N_BINS * N_CELLS );
341
return
features[featureIdx].calc( hist, normSum, sampleIdx, componentIdx );
344
inline
float
CvHOGEvaluator::Feature::calc(
const
std::vector<Mat>& _hists,
const
Mat& _normSum,
size_t
y,
int
featComponent )
const
349
int
binIdx = featComponent % N_BINS;
350
int
cellIdx = featComponent / N_BINS;
352
const
float
*phist = _hists[binIdx].ptr<
float>( (int) y );
353
res = phist[fastRect[cellIdx].p0] - phist[fastRect[cellIdx].p1] - phist[fastRect[cellIdx].p2] + phist[fastRect[cellIdx].p3];
355
const
float
*pnormSum = _normSum.ptr<
float>( (int) y );
356
normFactor = (float) ( pnormSum[fastRect[0].p0] - pnormSum[fastRect[1].p1] - pnormSum[fastRect[2].p2] + pnormSum[fastRect[3].p3] );
357
res = ( res > 0.001f ) ? ( res / ( normFactor + 0.001f ) ) : 0.f;
374
virtual
void
init(
const
CvFeatureParams
*_featureParams,
int
_maxSampleCount,
Size
_winSize ) CV_OVERRIDE;
375
virtual
void
setImage(
const
Mat& img, uchar clsLabel,
int
idx ) CV_OVERRIDE;
376
virtual
float
operator()(
int
featureIdx,
int
sampleIdx ) CV_OVERRIDE
378
return
(
float) features[featureIdx].calc( sum, sampleIdx );
380
virtual
void
writeFeatures(
FileStorage
&fs,
const
Mat& featureMap )
const
CV_OVERRIDE;
382
virtual
void
generateFeatures() CV_OVERRIDE;
388
Feature(
int
offset,
int
x,
int
y,
int
_block_w,
int
_block_h );
389
uchar calc(
const
Mat& _sum,
size_t
y )
const;
395
std::vector<Feature> features;
400
inline
uchar CvLBPEvaluator::Feature::calc(
const
Mat
&_sum,
size_t
y )
const
402
const
int* psum = _sum.
ptr<
int>( (int) y );
403
int
cval = psum[p[5]] - psum[p[6]] - psum[p[9]] + psum[p[10]];
405
return
(uchar) ( ( psum[p[0]] - psum[p[1]] - psum[p[4]] + psum[p[5]] >= cval ? 128 : 0 ) |
406
( psum[p[1]] - psum[p[2]] - psum[p[5]] + psum[p[6]] >= cval ? 64 : 0 ) |
407
( psum[p[2]] - psum[p[3]] - psum[p[6]] + psum[p[7]] >= cval ? 32 : 0 ) |
408
( psum[p[6]] - psum[p[7]] - psum[p[10]] + psum[p[11]] >= cval ? 16 : 0 ) |
409
( psum[p[10]] - psum[p[11]] - psum[p[14]] + psum[p[15]] >= cval ? 8 : 0 ) |
410
( psum[p[9]] - psum[p[10]] - psum[p[13]] + psum[p[14]] >= cval ? 4 : 0 ) |
411
( psum[p[8]] - psum[p[9]] - psum[p[12]] + psum[p[13]] >= cval ? 2 : 0 ) |
412
( psum[p[4]] - psum[p[5]] - psum[p[8]] + psum[p[9]] >= cval ? 1 : 0 ) );
File Storage Node class.
Definition:
persistence.hpp:482
XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or readi...
Definition:
persistence.hpp:304
Template matrix class derived from Mat
Definition:
mat.hpp:2199
n-dimensional dense array class
Definition:
mat.hpp:802
uchar * ptr(int i0=0)
Returns a pointer to the specified matrix row.
_Tp & at(int i0=0)
Returns a reference to the specified array element.
Template class for 2D rectangles
Definition:
core/types.hpp:421
Template class for specifying the size of an image or rectangle.
Definition:
core/types.hpp:316
Definition:
feature.hpp:161
Definition:
feature.hpp:141
Definition:
feature.hpp:315
Definition:
feature.hpp:302
Definition:
feature.hpp:224
Definition:
feature.hpp:220
Definition:
feature.hpp:203
Definition:
feature.hpp:385
Definition:
feature.hpp:369
Definition:
feature.hpp:124
CV_EXPORTS void split(const Mat &src, Mat *mvbegin)
Divides a multi-channel array into several single-channel arrays.
CV_EXPORTS_W double norm(InputArray src1, int normType=NORM_L2, InputArray mask=noArray())
Calculates the absolute norm of an array.
CV_EXPORTS_W void integral(InputArray src, OutputArray sum, int sdepth=-1)
"black box" representation of the file storage associated with a file on disk.
Definition:
aruco.hpp:75
Definition:
cvstd_wrapper.hpp:74
Definition:
feature.hpp:297
Definition:
feature.hpp:363