Ocean
ORBSamplingPattern.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_CV_DETECTOR_ORB_SAMPLING_PATTERN_H
9 #define META_OCEAN_CV_DETECTOR_ORB_SAMPLING_PATTERN_H
10 
12 
13 #include "ocean/math/Vector2.h"
14 
15 namespace Ocean
16 {
17 
18 namespace CV
19 {
20 
21 namespace Detector
22 {
23 
24 /**
25  * This singleton holds several lookup tables for the determination of ORB descriptors.
26  * It holds one lookup table for different feature orientations.
27  * These number is defined by a member variable that graduates the range of the angle of the orientation (in radian [0, 2*PI)) in several increments.
28  * A lookup table contains 256 sets of two 2D coordinates that define the position of a binary test during the ORB descriptor calculation.
29  * @ingroup cvdetector
30  */
31 class OCEAN_CV_DETECTOR_EXPORT ORBSamplingPattern : public Singleton<ORBSamplingPattern>
32 {
33  friend class Singleton<ORBSamplingPattern>;
34 
35  public:
36 
37  /**
38  * This class holds 2D coordinates of two points which are used for a binary test during the ORB descriptor calculation.
39  * The stored coordinates are offset values that must be added to the feature point observation during a test.
40  */
42  {
43  friend class ORBSamplingPattern;
44 
45  public:
46 
47  /**
48  * Default constructor.
49  */
50  LookupPosition() = default;
51 
52  /**
53  * Returns the first lookup point.
54  * @return The first lookup point
55  */
56  inline const Vector2& point0() const;
57 
58  /**
59  * Returns the second lookup point.
60  * @return The second lookup point
61  */
62  inline const Vector2& point1() const;
63 
64  protected:
65 
66  /**
67  * Set the coordinates of the two points.
68  * @param point0 The first point to set
69  * @param point1 The second point to set
70  */
71  inline void setPositions(const Vector2& point0, const Vector2& point1);
72 
73  protected:
74 
75  /// The first point.
77 
78  /// The second point.
80  };
81 
82  /**
83  * Definition of a vector holding LookupPosition objects.
84  */
85  using LookupTable = std::vector<LookupPosition>;
86 
87  protected:
88 
89  /**
90  * Definition of a vector holding lookup tables.
91  */
92  using LookupTables = std::vector<LookupTable>;
93 
94  public:
95 
96  /**
97  * Returns a vector of sampling pattern lookup tables for all angle increments.
98  * @return Sampling pattern lookup tables
99  */
100  inline const LookupTables& samplingPatterns() const;
101 
102  /**
103  * Returns the lookup table of a sampling pattern for a given angle.
104  * @param angle The angle for which the lookup table is requested, in radian, with range [0, 2*PI)
105  * @return The lookup table with the individual sampling patterns for the given angle, lookup locations with be within the range (-18.385, 18.385)x(-18.385, 18.385)
106  */
107  inline const LookupTable& samplingPatternForAngle(const Scalar angle) const;
108 
109  protected:
110 
111  /**
112  * Creates a new ORBSamplingPattern object.
113  */
115 
116  /**
117  * Creates the sampling pattern lookup tables for the ORB feature descriptor calculation tests.
118  * The number of tables is equal to the given angle increments
119  * @param angleIncrements The number of increments of a full rotation (must match with the corresponding value of this class)
120  * @return The lookup table
121  */
122  static LookupTables createLookupTables(const unsigned int angleIncrements);
123 
124  protected:
125 
126  // Number of increments of a full rotation, with range [1, 360]
127  static constexpr unsigned int angleIncrements_ = 72u;
128 
129  // Represents 1 / (angle per increment)
130  static constexpr Scalar anglePerIncrementFactor_ = Scalar(angleIncrements_) / Numeric::pi2();
131 
132  // Sampling pattern lookup tables
134 
135 };
136 
138 {
139  return point0_;
140 }
141 
143 {
144  return point1_;
145 }
146 
147 inline void ORBSamplingPattern::LookupPosition::setPositions(const Vector2& point0, const Vector2& point1)
148 {
149  point0_ = point0;
150  point1_ = point1;
151 
152  ocean_assert(point0_ != point1_);
153 }
154 
156 {
157  return lookupTables_;
158 }
159 
161 {
162  ocean_assert(angle >= Scalar(0) && angle < Numeric::pi2());
163 
164  return lookupTables_[(unsigned int)(angle * anglePerIncrementFactor_ + Scalar(0.5)) % angleIncrements_];
165 }
166 
167 }
168 
169 }
170 
171 }
172 
173 #endif // META_OCEAN_CV_DETECTOR_ORB_SAMPLING_PATTERN_H
This class holds 2D coordinates of two points which are used for a binary test during the ORB descrip...
Definition: ORBSamplingPattern.h:42
const Vector2 & point1() const
Returns the second lookup point.
Definition: ORBSamplingPattern.h:142
Vector2 point0_
The first point.
Definition: ORBSamplingPattern.h:76
const Vector2 & point0() const
Returns the first lookup point.
Definition: ORBSamplingPattern.h:137
Vector2 point1_
The second point.
Definition: ORBSamplingPattern.h:79
void setPositions(const Vector2 &point0, const Vector2 &point1)
Set the coordinates of the two points.
Definition: ORBSamplingPattern.h:147
This singleton holds several lookup tables for the determination of ORB descriptors.
Definition: ORBSamplingPattern.h:32
const LookupTables & samplingPatterns() const
Returns a vector of sampling pattern lookup tables for all angle increments.
Definition: ORBSamplingPattern.h:155
std::vector< LookupTable > LookupTables
Definition of a vector holding lookup tables.
Definition: ORBSamplingPattern.h:92
const LookupTables lookupTables_
Definition: ORBSamplingPattern.h:133
std::vector< LookupPosition > LookupTable
Definition of a vector holding LookupPosition objects.
Definition: ORBSamplingPattern.h:85
static constexpr Scalar anglePerIncrementFactor_
Definition: ORBSamplingPattern.h:130
static constexpr unsigned int angleIncrements_
Definition: ORBSamplingPattern.h:127
static LookupTables createLookupTables(const unsigned int angleIncrements)
Creates the sampling pattern lookup tables for the ORB feature descriptor calculation tests.
const LookupTable & samplingPatternForAngle(const Scalar angle) const
Returns the lookup table of a sampling pattern for a given angle.
Definition: ORBSamplingPattern.h:160
ORBSamplingPattern()
Creates a new ORBSamplingPattern object.
static constexpr T pi2()
Returns 2*PI which is equivalent to 360 degree.
Definition: Numeric.h:932
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15