-
Notifications
You must be signed in to change notification settings - Fork 26
/
BAD.h
99 lines (86 loc) · 3.74 KB
/
BAD.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* @copyright 2021 Xoan Iago Suarez Canosa. All rights reserved.
* Constact: iago.suarez@thegraffter.com
* Software developed in the PhD: Low-level vision for resource-limited devices
*/
#ifndef EFFICIENT_DESCRIPTORS_BAD_H_
#define EFFICIENT_DESCRIPTORS_BAD_H_
#include <vector>
#include <opencv2/opencv.hpp>
namespace upm {
/**
* Implementation of the Box Average Difference (BAD) descriptor. The method uses features
* computed from the difference of the average gray values of two boxes in the patch.
*
* Each pair of boxes is represented with a BoxPairParams struct. After obtaining the feature
* from them, the i'th feature is thresholded with thresholds_[i], producing the binary
* weak-descriptor.
*/
class BAD : public cv::Feature2D {
public:
/**
* @brief Descriptor number of bits, each bit is a weak-descriptor.
* The user can choose between 512 or 256 bits.
*/
enum BadSize {
SIZE_512_BITS = 100, SIZE_256_BITS = 101,
};
/**
* @param scale_factor Adjust the sampling window around detected keypoints:
- <b> 1.00f </b> should be the scale for ORB keypoints
- <b> 6.75f </b> should be the scale for SIFT detected keypoints
- <b> 6.25f </b> is default and fits for KAZE, SURF detected keypoints
- <b> 5.00f </b> should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints
* @param n_bits Determine the number of bits in the descriptor. Should be either
BAD::SIZE_512_BITS or BAD::SIZE_256_BITS.
*/
explicit BAD(float scale_factor = 1.0f, BadSize n_bits = SIZE_512_BITS);
/**
* @brief Creates the BAD descriptor.
* @param scale_factor Adjust the sampling window around detected keypoints:
- <b> 1.00f </b> should be the scale for ORB keypoints
- <b> 6.75f </b> should be the scale for SIFT detected keypoints
- <b> 6.25f </b> is default and fits for KAZE, SURF detected keypoints
- <b> 5.00f </b> should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints
* @param n_bits
* @return
*/
static cv::Ptr<BAD> create(float scale_factor = 1.0f, BadSize n_bits = SIZE_512_BITS) {
return cv::makePtr<upm::BAD>(scale_factor, n_bits);
}
/** @brief Computes the descriptors for a set of keypoints detected in an image (first variant) or image set
(second variant).
@param image Image.
@param keypoints Input collection of keypoints. Keypoints for which a descriptor cannot be
computed are removed. Sometimes new keypoints can be added, for example: SIFT duplicates keypoint
with several dominant orientations (for each orientation).
@param descriptors Computed descriptors. In the second variant of the method descriptors[i] are
descriptors computed for a keypoints[i]. Row j is the keypoints (or keypoints[i]) is the
descriptor for keypoint j-th keypoint.
*/
void compute(cv::InputArray image,
CV_OUT CV_IN_OUT std::vector<cv::KeyPoint> &keypoints,
cv::OutputArray descriptors) override;
int descriptorSize() const override { return box_params_.size() / 8; }
int descriptorType() const override { return CV_8UC1; }
int defaultNorm() const override { return cv::NORM_HAMMING; }
bool empty() const override { return false; }
cv::String getDefaultName() const override {
return std::string("BAD") + std::to_string(box_params_.size());
}
// Struct representing a pair of boxes in the patch
struct BoxPairParams {
int x1, x2, y1, y2, boxRadius;
};
protected:
// Computes the BADdescriptor
void computeBAD(const cv::Mat &integral_img,
const std::vector<cv::KeyPoint> &keypoints,
cv::Mat &descriptors);
std::vector<float> thresholds_;
std::vector<BoxPairParams> box_params_;
float scale_factor_ = 1;
cv::Size patch_size_ = {32, 32};
};
}
#endif //EFFICIENT_DESCRIPTORS_BAD_H_