@@ -30,14 +30,21 @@ struct ABWLParams
30
30
{
31
31
int x1, y1, x2, y2, boxRadius, th;
32
32
};
33
+ // Same as previous with floating point threshold
34
+ struct ABWLParamsFloatTh
35
+ {
36
+ int x1, y1, x2, y2, boxRadius;
37
+ float th;
38
+ };
33
39
34
40
// BEBLID implementation
41
+ template <class WeakLearnerT >
35
42
class BEBLID_Impl CV_FINAL: public BEBLID
36
43
{
37
44
public:
38
45
39
46
// constructor
40
- explicit BEBLID_Impl (float scale_factor, int n_bits = SIZE_512_BITS );
47
+ explicit BEBLID_Impl (float scale_factor, const std::vector<WeakLearnerT>& wl_params );
41
48
42
49
// destructor
43
50
~BEBLID_Impl () CV_OVERRIDE = default ;
@@ -55,15 +62,65 @@ class BEBLID_Impl CV_FINAL: public BEBLID
55
62
void compute (InputArray image, vector<KeyPoint> &keypoints, OutputArray descriptors) CV_OVERRIDE;
56
63
57
64
private:
58
- std::vector<ABWLParams > wl_params_;
65
+ std::vector<WeakLearnerT > wl_params_;
59
66
float scale_factor_;
60
67
cv::Size patch_size_;
61
68
62
- void computeBEBLID (const cv::Mat &integralImg,
63
- const std::vector<cv::KeyPoint> &keypoints,
64
- cv::Mat &descriptors);
69
+ void computeBoxDiffsDescriptor (const cv::Mat &integralImg,
70
+ const std::vector<cv::KeyPoint> &keypoints,
71
+ cv::Mat &descriptors);
65
72
}; // END BEBLID_Impl CLASS
66
73
74
+
75
+ // TEBLID implementation
76
+ class TEBLID_Impl CV_FINAL: public TEBLID
77
+ {
78
+ public:
79
+
80
+ // constructor
81
+ explicit TEBLID_Impl (float scale_factor, const std::vector<ABWLParamsFloatTh>& wl_params) :
82
+ impl(scale_factor, wl_params){}
83
+
84
+ // destructor
85
+ ~TEBLID_Impl () CV_OVERRIDE = default ;
86
+
87
+ // returns the descriptor length in bytes
88
+ int descriptorSize () const CV_OVERRIDE { return impl.descriptorSize (); }
89
+
90
+ // returns the descriptor type
91
+ int descriptorType () const CV_OVERRIDE { return impl.descriptorType (); }
92
+
93
+ // returns the default norm type
94
+ int defaultNorm () const CV_OVERRIDE { return impl.defaultNorm (); }
95
+
96
+ // compute descriptors given keypoints
97
+ void compute (InputArray image, vector<KeyPoint> &keypoints, OutputArray descriptors) CV_OVERRIDE
98
+ {
99
+ impl.compute (image, keypoints, descriptors);
100
+ }
101
+
102
+ private:
103
+ BEBLID_Impl<ABWLParamsFloatTh> impl;
104
+ }; // END TEBLID_Impl CLASS
105
+
106
+ Ptr<TEBLID> TEBLID::create (float scale_factor, int n_bits)
107
+ {
108
+ if (n_bits == TEBLID::SIZE_512_BITS)
109
+ {
110
+ #include " teblid.p512.hpp"
111
+ return makePtr<TEBLID_Impl>(scale_factor, teblid_wl_params_512);
112
+ }
113
+ else if (n_bits == TEBLID::SIZE_256_BITS)
114
+ {
115
+ #include " teblid.p256.hpp"
116
+ return makePtr<TEBLID_Impl>(scale_factor, teblid_wl_params_256);
117
+ }
118
+ else
119
+ {
120
+ CV_Error (Error::StsBadArg, " n_bits should be either TEBLID::SIZE_512_BITS or TEBLID::SIZE_256_BITS" );
121
+ }
122
+ }
123
+
67
124
/* *
68
125
* @brief Function that determines if a keypoint is close to the image border.
69
126
* @param kp The detected keypoint
@@ -100,8 +157,9 @@ static inline bool isKeypointInTheBorder(const cv::KeyPoint &kp,
100
157
* @param scaleFactor A scale factor that magnifies the measurement functions w.r.t. the keypoint.
101
158
* @param patchSize The size of the normalized patch where the measurement functions were learnt.
102
159
*/
103
- static inline void rectifyABWL (const std::vector<ABWLParams> &wlPatchParams,
104
- std::vector<ABWLParams> &wlImageParams,
160
+ template < typename WeakLearnerT>
161
+ static inline void rectifyABWL (const std::vector<WeakLearnerT> &wlPatchParams,
162
+ std::vector<WeakLearnerT> &wlImageParams,
105
163
const cv::KeyPoint &kp,
106
164
float scaleFactor = 1 ,
107
165
const cv::Size &patchSize = cv::Size(32 , 32 ))
@@ -151,7 +209,8 @@ static inline void rectifyABWL(const std::vector<ABWLParams> &wlPatchParams,
151
209
* @param integralImage The integral image used to compute the average gray value in the square regions.
152
210
* @return The difference of gray level in the two squares defined by wlImageParams
153
211
*/
154
- static inline float computeABWLResponse (const ABWLParams &wlImageParams,
212
+ template <typename WeakLearnerT>
213
+ static inline float computeABWLResponse (const WeakLearnerT &wlImageParams,
155
214
const cv::Mat &integralImage)
156
215
{
157
216
CV_DbgAssert (!integralImage.empty ());
@@ -239,7 +298,8 @@ static inline float computeABWLResponse(const ABWLParams &wlImageParams,
239
298
}
240
299
241
300
// descriptor computation using keypoints
242
- void BEBLID_Impl::compute (InputArray _image, vector<KeyPoint> &keypoints, OutputArray _descriptors)
301
+ template <class WeakLearnerT >
302
+ void BEBLID_Impl<WeakLearnerT>::compute(InputArray _image, vector<KeyPoint> &keypoints, OutputArray _descriptors)
243
303
{
244
304
Mat image = _image.getMat ();
245
305
@@ -281,27 +341,21 @@ void BEBLID_Impl::compute(InputArray _image, vector<KeyPoint> &keypoints, Output
281
341
CV_DbgAssert (descriptors.type () == CV_8UC1);
282
342
283
343
// Compute the BEBLID descriptors
284
- computeBEBLID (integralImg, keypoints, descriptors);
344
+ computeBoxDiffsDescriptor (integralImg, keypoints, descriptors);
285
345
}
286
346
287
347
// constructor
288
- BEBLID_Impl::BEBLID_Impl (float scale_factor, int n_bits)
289
- : scale_factor_(scale_factor), patch_size_(32 , 32 )
348
+ template <class WeakLearnerT >
349
+ BEBLID_Impl<WeakLearnerT>::BEBLID_Impl(float scale_factor, const std::vector<WeakLearnerT>& wl_params)
350
+ : wl_params_(wl_params), scale_factor_(scale_factor),patch_size_(32 , 32 )
290
351
{
291
- #include " beblid.p512.hpp"
292
- #include " beblid.p256.hpp"
293
- if (n_bits == SIZE_512_BITS)
294
- wl_params_.assign (wl_params_512, wl_params_512 + sizeof (wl_params_512) / sizeof (wl_params_512[0 ]));
295
- else if (n_bits == SIZE_256_BITS)
296
- wl_params_.assign (wl_params_256, wl_params_256 + sizeof (wl_params_256) / sizeof (wl_params_256[0 ]));
297
- else
298
- CV_Error (Error::StsBadArg, " n_wls should be either SIZE_512_BITS or SIZE_256_BITS" );
299
352
}
300
353
301
354
// Internal function that implements the core of BEBLID descriptor
302
- void BEBLID_Impl::computeBEBLID (const cv::Mat &integralImg,
303
- const std::vector<cv::KeyPoint> &keypoints,
304
- cv::Mat &descriptors)
355
+ template <class WeakLearnerT >
356
+ void BEBLID_Impl<WeakLearnerT>::computeBoxDiffsDescriptor(const cv::Mat &integralImg,
357
+ const std::vector<cv::KeyPoint> &keypoints,
358
+ cv::Mat &descriptors)
305
359
{
306
360
CV_DbgAssert (!integralImg.empty ());
307
361
CV_DbgAssert (size_t (descriptors.rows ) == keypoints.size ());
@@ -316,13 +370,13 @@ void BEBLID_Impl::computeBEBLID(const cv::Mat &integralImg,
316
370
#endif
317
371
{
318
372
// Get a pointer to the first element in the range
319
- ABWLParams *wl;
373
+ WeakLearnerT *wl;
320
374
float responseFun;
321
375
int areaResponseFun, kpIdx;
322
376
size_t wlIdx;
323
377
int box1x1, box1y1, box1x2, box1y2, box2x1, box2y1, box2x2, box2y2, bit_idx, side;
324
378
uchar byte = 0 ;
325
- std::vector<ABWLParams > imgWLParams (wl_params_.size ());
379
+ std::vector<WeakLearnerT > imgWLParams (wl_params_.size ());
326
380
uchar *d = &descriptors.at <uchar>(range.start , 0 );
327
381
328
382
for (kpIdx = range.start ; kpIdx < range.end ; kpIdx++)
@@ -397,7 +451,20 @@ void BEBLID_Impl::computeBEBLID(const cv::Mat &integralImg,
397
451
398
452
Ptr<BEBLID> BEBLID::create (float scale_factor, int n_bits)
399
453
{
400
- return makePtr<BEBLID_Impl>(scale_factor, n_bits);
454
+ if (n_bits == BEBLID::SIZE_512_BITS)
455
+ {
456
+ #include " beblid.p512.hpp"
457
+ return makePtr<BEBLID_Impl<ABWLParams>>(scale_factor, beblid_wl_params_512);
458
+ }
459
+ else if (n_bits == BEBLID::SIZE_256_BITS)
460
+ {
461
+ #include " beblid.p256.hpp"
462
+ return makePtr<BEBLID_Impl<ABWLParams>>(scale_factor, beblid_wl_params_256);
463
+ }
464
+ else
465
+ {
466
+ CV_Error (Error::StsBadArg, " n_bits should be either BEBLID::SIZE_512_BITS or BEBLID::SIZE_256_BITS" );
467
+ }
401
468
}
402
469
} // END NAMESPACE XFEATURES2D
403
470
} // END NAMESPACE CV
0 commit comments