@@ -30,14 +30,21 @@ struct ABWLParams
3030{
3131 int x1, y1, x2, y2, boxRadius, th;
3232};
33+ // Same as previous with floating point threshold
34+ struct ABWLParamsFloatTh
35+ {
36+ int x1, y1, x2, y2, boxRadius;
37+ float th;
38+ };
3339
3440// BEBLID implementation
41+ template <class WeakLearnerT >
3542class BEBLID_Impl CV_FINAL: public BEBLID
3643{
3744public:
3845
3946 // 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 );
4148
4249 // destructor
4350 ~BEBLID_Impl () CV_OVERRIDE = default ;
@@ -55,15 +62,65 @@ class BEBLID_Impl CV_FINAL: public BEBLID
5562 void compute (InputArray image, vector<KeyPoint> &keypoints, OutputArray descriptors) CV_OVERRIDE;
5663
5764private:
58- std::vector<ABWLParams > wl_params_;
65+ std::vector<WeakLearnerT > wl_params_;
5966 float scale_factor_;
6067 cv::Size patch_size_;
6168
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);
6572}; // END BEBLID_Impl CLASS
6673
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+
67124/* *
68125 * @brief Function that determines if a keypoint is close to the image border.
69126 * @param kp The detected keypoint
@@ -100,8 +157,9 @@ static inline bool isKeypointInTheBorder(const cv::KeyPoint &kp,
100157 * @param scaleFactor A scale factor that magnifies the measurement functions w.r.t. the keypoint.
101158 * @param patchSize The size of the normalized patch where the measurement functions were learnt.
102159 */
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,
105163 const cv::KeyPoint &kp,
106164 float scaleFactor = 1 ,
107165 const cv::Size &patchSize = cv::Size(32 , 32 ))
@@ -151,7 +209,8 @@ static inline void rectifyABWL(const std::vector<ABWLParams> &wlPatchParams,
151209 * @param integralImage The integral image used to compute the average gray value in the square regions.
152210 * @return The difference of gray level in the two squares defined by wlImageParams
153211 */
154- static inline float computeABWLResponse (const ABWLParams &wlImageParams,
212+ template <typename WeakLearnerT>
213+ static inline float computeABWLResponse (const WeakLearnerT &wlImageParams,
155214 const cv::Mat &integralImage)
156215{
157216 CV_DbgAssert (!integralImage.empty ());
@@ -239,7 +298,8 @@ static inline float computeABWLResponse(const ABWLParams &wlImageParams,
239298}
240299
241300// 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)
243303{
244304 Mat image = _image.getMat ();
245305
@@ -281,27 +341,21 @@ void BEBLID_Impl::compute(InputArray _image, vector<KeyPoint> &keypoints, Output
281341 CV_DbgAssert (descriptors.type () == CV_8UC1);
282342
283343 // Compute the BEBLID descriptors
284- computeBEBLID (integralImg, keypoints, descriptors);
344+ computeBoxDiffsDescriptor (integralImg, keypoints, descriptors);
285345}
286346
287347// 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 )
290351{
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" );
299352}
300353
301354// 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)
305359{
306360 CV_DbgAssert (!integralImg.empty ());
307361 CV_DbgAssert (size_t (descriptors.rows ) == keypoints.size ());
@@ -316,13 +370,13 @@ void BEBLID_Impl::computeBEBLID(const cv::Mat &integralImg,
316370#endif
317371 {
318372 // Get a pointer to the first element in the range
319- ABWLParams *wl;
373+ WeakLearnerT *wl;
320374 float responseFun;
321375 int areaResponseFun, kpIdx;
322376 size_t wlIdx;
323377 int box1x1, box1y1, box1x2, box1y2, box2x1, box2y1, box2x2, box2y2, bit_idx, side;
324378 uchar byte = 0 ;
325- std::vector<ABWLParams > imgWLParams (wl_params_.size ());
379+ std::vector<WeakLearnerT > imgWLParams (wl_params_.size ());
326380 uchar *d = &descriptors.at <uchar>(range.start , 0 );
327381
328382 for (kpIdx = range.start ; kpIdx < range.end ; kpIdx++)
@@ -397,7 +451,20 @@ void BEBLID_Impl::computeBEBLID(const cv::Mat &integralImg,
397451
398452Ptr<BEBLID> BEBLID::create (float scale_factor, int n_bits)
399453{
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+ }
401468}
402469} // END NAMESPACE XFEATURES2D
403470} // END NAMESPACE CV
0 commit comments