@@ -27,12 +27,18 @@ namespace xfeatures2d
27
27
28
28
// Struct containing the 6 parameters that define an Average Box weak-learner
29
29
struct ABWLParams
30
+ {
31
+ int x1, y1, x2, y2, boxRadius, th;
32
+ };
33
+ // Same as previous with floating point threshold
34
+ struct ABWLParamsFloatTh
30
35
{
31
36
int x1, y1, x2, y2, boxRadius;
32
37
float th;
33
38
};
34
39
35
40
// BEBLID implementation
41
+ template <class WeakLearnerT >
36
42
class BEBLID_Impl CV_FINAL: public BEBLID
37
43
{
38
44
public:
@@ -56,26 +62,26 @@ class BEBLID_Impl CV_FINAL: public BEBLID
56
62
void compute (InputArray image, vector<KeyPoint> &keypoints, OutputArray descriptors) CV_OVERRIDE;
57
63
58
64
private:
59
- std::vector<ABWLParams > wl_params_;
65
+ std::vector<WeakLearnerT > wl_params_;
60
66
float scale_factor_;
61
67
cv::Size patch_size_;
62
68
63
- void computeBEBLID (const cv::Mat &integralImg,
64
- const std::vector<cv::KeyPoint> &keypoints,
65
- cv::Mat &descriptors);
69
+ void computeBoxDiffsDescriptor (const cv::Mat &integralImg,
70
+ const std::vector<cv::KeyPoint> &keypoints,
71
+ cv::Mat &descriptors);
66
72
}; // END BEBLID_Impl CLASS
67
73
68
74
69
- // BAD implementation
70
- class BAD_Impl CV_FINAL: public BAD
75
+ // TEBLID implementation
76
+ class TEBLID_Impl CV_FINAL: public TEBLID
71
77
{
72
78
public:
73
79
74
80
// constructor
75
- explicit BAD_Impl (float scale_factor, int n_bits = BAD ::SIZE_256_BITS) : impl(scale_factor, n_bits){}
81
+ explicit TEBLID_Impl (float scale_factor, int n_bits = TEBLID ::SIZE_256_BITS) : impl(scale_factor, n_bits){}
76
82
77
83
// destructor
78
- ~BAD_Impl () CV_OVERRIDE = default ;
84
+ ~TEBLID_Impl () CV_OVERRIDE = default ;
79
85
80
86
// returns the descriptor length in bytes
81
87
int descriptorSize () const CV_OVERRIDE { return impl.descriptorSize (); }
@@ -93,12 +99,12 @@ class BAD_Impl CV_FINAL: public BAD
93
99
}
94
100
95
101
private:
96
- BEBLID_Impl impl;
97
- }; // END BAD_Impl CLASS
102
+ BEBLID_Impl<ABWLParamsFloatTh> impl;
103
+ }; // END TEBLID_Impl CLASS
98
104
99
- Ptr <BAD> BAD ::create (float scale_factor, int n_bits)
105
+ Ptr <TEBLID> TEBLID ::create (float scale_factor, int n_bits)
100
106
{
101
- return makePtr<BAD_Impl >(scale_factor, n_bits);
107
+ return makePtr<TEBLID_Impl >(scale_factor, n_bits);
102
108
}
103
109
104
110
/* *
@@ -137,8 +143,9 @@ static inline bool isKeypointInTheBorder(const cv::KeyPoint &kp,
137
143
* @param scaleFactor A scale factor that magnifies the measurement functions w.r.t. the keypoint.
138
144
* @param patchSize The size of the normalized patch where the measurement functions were learnt.
139
145
*/
140
- static inline void rectifyABWL (const std::vector<ABWLParams> &wlPatchParams,
141
- std::vector<ABWLParams> &wlImageParams,
146
+ template < typename WeakLearnerT>
147
+ static inline void rectifyABWL (const std::vector<WeakLearnerT> &wlPatchParams,
148
+ std::vector<WeakLearnerT> &wlImageParams,
142
149
const cv::KeyPoint &kp,
143
150
float scaleFactor = 1 ,
144
151
const cv::Size &patchSize = cv::Size (32 , 32 ))
@@ -188,7 +195,8 @@ static inline void rectifyABWL(const std::vector<ABWLParams> &wlPatchParams,
188
195
* @param integralImage The integral image used to compute the average gray value in the square regions.
189
196
* @return The difference of gray level in the two squares defined by wlImageParams
190
197
*/
191
- static inline float computeABWLResponse (const ABWLParams &wlImageParams,
198
+ template <typename WeakLearnerT>
199
+ static inline float computeABWLResponse (const WeakLearnerT &wlImageParams,
192
200
const cv::Mat &integralImage)
193
201
{
194
202
CV_DbgAssert (!integralImage.empty ());
@@ -276,7 +284,8 @@ static inline float computeABWLResponse(const ABWLParams &wlImageParams,
276
284
}
277
285
278
286
// descriptor computation using keypoints
279
- void BEBLID_Impl::compute (InputArray _image, vector<KeyPoint> &keypoints, OutputArray _descriptors)
287
+ template <class WeakLearnerT >
288
+ void BEBLID_Impl<WeakLearnerT>::compute(InputArray _image, vector<KeyPoint> &keypoints, OutputArray _descriptors)
280
289
{
281
290
Mat image = _image.getMat ();
282
291
@@ -318,45 +327,52 @@ void BEBLID_Impl::compute(InputArray _image, vector<KeyPoint> &keypoints, Output
318
327
CV_DbgAssert (descriptors.type () == CV_8UC1);
319
328
320
329
// Compute the BEBLID descriptors
321
- computeBEBLID (integralImg, keypoints, descriptors);
330
+ computeBoxDiffsDescriptor (integralImg, keypoints, descriptors);
322
331
}
323
332
324
333
// constructor
325
- BEBLID_Impl::BEBLID_Impl (float scale_factor, int n_bits)
334
+ template <class WeakLearnerT >
335
+ BEBLID_Impl<WeakLearnerT>::BEBLID_Impl(float scale_factor, int n_bits)
326
336
: scale_factor_(scale_factor), patch_size_(32 , 32 )
327
337
{
338
+ WeakLearnerT * begin_ptr, * end_ptr;
328
339
if (n_bits == BEBLID::SIZE_512_BITS)
329
340
{
330
341
#include " beblid.p512.hpp"
331
- wl_params_.assign (wl_params_512, wl_params_512 + sizeof (wl_params_512) / sizeof (wl_params_512[0 ]));
342
+ begin_ptr = (WeakLearnerT *) std::begin (wl_params_512);
343
+ end_ptr = (WeakLearnerT *) std::end (wl_params_512);
332
344
}
333
345
else if (n_bits == BEBLID::SIZE_256_BITS)
334
346
{
335
347
#include " beblid.p256.hpp"
336
- wl_params_.assign (wl_params_256, wl_params_256 + sizeof (wl_params_256) / sizeof (wl_params_256[0 ]));
348
+ begin_ptr = (WeakLearnerT *) std::begin (wl_params_256);
349
+ end_ptr = (WeakLearnerT *) std::end (wl_params_256);
337
350
}
338
- else if (n_bits == BAD ::SIZE_512_BITS)
351
+ else if (n_bits == TEBLID ::SIZE_512_BITS)
339
352
{
340
353
#include " bad.p512.hpp"
341
- wl_params_.assign (bad_params_512, bad_params_512 + sizeof (bad_params_512) / sizeof (bad_params_512[0 ]));
354
+ begin_ptr = (WeakLearnerT *) std::begin (bad_params_512);
355
+ end_ptr = (WeakLearnerT *) std::end (bad_params_512);
342
356
}
343
- else if (n_bits == BAD ::SIZE_256_BITS)
357
+ else if (n_bits == TEBLID ::SIZE_256_BITS)
344
358
{
345
359
#include " bad.p256.hpp"
346
- wl_params_.assign (bad_params_256, bad_params_256 + sizeof (bad_params_256) / sizeof (bad_params_256[0 ]));
360
+ begin_ptr = (WeakLearnerT *) std::begin (bad_params_256);
361
+ end_ptr = (WeakLearnerT *) std::end (bad_params_256);
347
362
}
348
363
else
349
364
{
350
- CV_Error (Error::StsBadArg, " n_bits should be either BAD ::SIZE_512_BITS, BAD ::SIZE_256_BITS, "
365
+ CV_Error (Error::StsBadArg, " n_bits should be either TEBLID ::SIZE_512_BITS, TEBLID ::SIZE_256_BITS, "
351
366
" BEBLID::SIZE_512_BITS or BEBLID::SIZE_256_BITS" );
352
367
}
353
-
368
+ wl_params_. assign (begin_ptr, end_ptr);
354
369
}
355
370
356
371
// Internal function that implements the core of BEBLID descriptor
357
- void BEBLID_Impl::computeBEBLID (const cv::Mat &integralImg,
358
- const std::vector<cv::KeyPoint> &keypoints,
359
- cv::Mat &descriptors)
372
+ template <class WeakLearnerT >
373
+ void BEBLID_Impl<WeakLearnerT>::computeBoxDiffsDescriptor(const cv::Mat &integralImg,
374
+ const std::vector<cv::KeyPoint> &keypoints,
375
+ cv::Mat &descriptors)
360
376
{
361
377
CV_DbgAssert (!integralImg.empty ());
362
378
CV_DbgAssert (size_t (descriptors.rows ) == keypoints.size ());
@@ -371,13 +387,13 @@ void BEBLID_Impl::computeBEBLID(const cv::Mat &integralImg,
371
387
#endif
372
388
{
373
389
// Get a pointer to the first element in the range
374
- ABWLParams *wl;
390
+ WeakLearnerT *wl;
375
391
float responseFun;
376
392
int areaResponseFun, kpIdx;
377
393
size_t wlIdx;
378
394
int box1x1, box1y1, box1x2, box1y2, box2x1, box2y1, box2x2, box2y2, bit_idx, side;
379
395
uchar byte = 0 ;
380
- std::vector<ABWLParams > imgWLParams (wl_params_.size ());
396
+ std::vector<WeakLearnerT > imgWLParams (wl_params_.size ());
381
397
uchar *d = &descriptors.at <uchar>(range.start , 0 );
382
398
383
399
for (kpIdx = range.start ; kpIdx < range.end ; kpIdx++)
@@ -452,7 +468,7 @@ void BEBLID_Impl::computeBEBLID(const cv::Mat &integralImg,
452
468
453
469
Ptr <BEBLID> BEBLID::create (float scale_factor, int n_bits)
454
470
{
455
- return makePtr<BEBLID_Impl>(scale_factor, n_bits);
471
+ return makePtr<BEBLID_Impl<ABWLParams> >(scale_factor, n_bits);
456
472
}
457
473
} // END NAMESPACE XFEATURES2D
458
474
} // END NAMESPACE CV
0 commit comments