Ocean
ORBDescriptor.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_DESCRIPTOR_H
9 #define META_OCEAN_CV_DETECTOR_ORB_DESCRIPTOR_H
10 
12 
14 
15 #include <bitset>
16 
17 namespace Ocean
18 {
19 
20 namespace CV
21 {
22 
23 namespace Detector
24 {
25 
26 // Forward declaration
27 class ORBDescriptor;
28 
29 /**
30  * Definition of a static vector holding up to three ORB descriptors.
31  * @ingroup cvdetector
32  */
34 
35 /**
36  * This class implement the descriptor for ORB features.
37  * A ORB descriptor consists of 256 bits.
38  * @ingroup cvdetector
39  */
41 {
42  public:
43 
44  /// The length of this descriptor in bits.
45  static constexpr size_t descriptorLengthInBits = 256;
46 
47  /**
48  * Definition of a bitset with 256 bits.
49  */
50  typedef std::bitset<descriptorLengthInBits> DescriptorBitset;
51 
52  public:
53 
54  /**
55  * Creates a new descriptor object holds zeros on every position.
56  */
57  inline ORBDescriptor();
58 
59  /**
60  * Creates a new descriptor object by a given bitset.
61  * @param bitset Bitset of the new descriptor
62  */
63  inline ORBDescriptor(const DescriptorBitset& bitset);
64 
65  /**
66  * Returns the bitset of the descriptor.
67  * @return Bitset
68  */
69  inline const DescriptorBitset& bitset() const;
70 
71  /**
72  * Returns the number of bits in the bitset of the descriptor that are set.
73  * @return Number of set bits
74  */
75  inline size_t count() const;
76 
77  /**
78  * Compares two descriptors and returns whether the left descriptor represents a smaller value than the right descriptor.
79  * @param rightDescriptor Descriptor to compare
80  * @return True, if so
81  */
82  inline bool operator<(const ORBDescriptor& rightDescriptor) const;
83 
84  /**
85  * Returns the descriptor holds a bitset that is the result of the XOR operation of the bitsets of two descriptors.
86  * @param rightDescriptor Right descriptor
87  * @return Resulting descriptor
88  */
89  inline ORBDescriptor operator^(const ORBDescriptor& rightDescriptor) const;
90 
91  /**
92  * Returns whether the bit of the bitset at a given index is set.
93  * @param index Index of the bit, range [0, 256]
94  * @return True, if so
95  */
96  inline bool operator[](const size_t index) const;
97 
98  /**
99  * Returns the reference to a bit of the descriptor bitset at a given index
100  * @param index Index of the bit, range [0, 256]
101  * @return Reference to the bit
102  */
103  inline DescriptorBitset::reference operator[](const size_t index);
104 
105  protected:
106 
107  // Bitset for the bits of the descriptor
109 };
110 
112 {
113  // nothing to do here
114 }
115 
117 {
118  descriptor = bitset;
119 }
120 
122 {
123  return descriptor;
124 }
125 
126 inline size_t ORBDescriptor::count() const
127 {
128  return descriptor.count();
129 }
130 
131 inline bool ORBDescriptor::operator<(const ORBDescriptor& rightDescriptor) const
132 {
133  const unsigned long long* valueLeft = (unsigned long long*)&descriptor;
134  const unsigned long long* valueRight = (unsigned long long*)&rightDescriptor.descriptor;
135 
136  return valueLeft[0] < valueRight[0]
137  || (valueLeft[0] == valueRight[0] && (valueLeft[1] < valueRight[1]
138  || (valueLeft[1] == valueRight[1] && (valueLeft[2] < valueRight[2]
139  || (valueLeft[2] == valueRight[2] && valueLeft[3] < valueRight[3])))));
140 }
141 
142 inline ORBDescriptor ORBDescriptor::operator^(const ORBDescriptor& rightDescriptor) const
143 {
144  return ORBDescriptor(descriptor ^ rightDescriptor.descriptor);
145 }
146 
147 inline bool ORBDescriptor::operator[](const size_t index) const
148 {
149  ocean_assert(index < sizeof(ORBDescriptor::DescriptorBitset) * 8);
150  return descriptor[index];
151 }
152 
153 inline ORBDescriptor::DescriptorBitset::reference ORBDescriptor::operator[](const size_t index)
154 {
155  ocean_assert(index < sizeof(ORBDescriptor::DescriptorBitset) * 8);
156  return descriptor[index];
157 }
158 
159 }
160 
161 }
162 
163 }
164 
165 #endif // META_OCEAN_CV_DETECTOR_ORB_DESCRIPTOR_H
This class implement the descriptor for ORB features.
Definition: ORBDescriptor.h:41
const DescriptorBitset & bitset() const
Returns the bitset of the descriptor.
Definition: ORBDescriptor.h:121
bool operator[](const size_t index) const
Returns whether the bit of the bitset at a given index is set.
Definition: ORBDescriptor.h:147
ORBDescriptor operator^(const ORBDescriptor &rightDescriptor) const
Returns the descriptor holds a bitset that is the result of the XOR operation of the bitsets of two d...
Definition: ORBDescriptor.h:142
std::bitset< descriptorLengthInBits > DescriptorBitset
Definition of a bitset with 256 bits.
Definition: ORBDescriptor.h:50
DescriptorBitset descriptor
Definition: ORBDescriptor.h:108
static constexpr size_t descriptorLengthInBits
The length of this descriptor in bits.
Definition: ORBDescriptor.h:45
size_t count() const
Returns the number of bits in the bitset of the descriptor that are set.
Definition: ORBDescriptor.h:126
ORBDescriptor()
Creates a new descriptor object holds zeros on every position.
Definition: ORBDescriptor.h:111
bool operator<(const ORBDescriptor &rightDescriptor) const
Compares two descriptors and returns whether the left descriptor represents a smaller value than the ...
Definition: ORBDescriptor.h:131
StaticVector< ORBDescriptor, 3 > ORBDescriptors
Definition of a static vector holding up to three ORB descriptors.
Definition: ORBDescriptor.h:27
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15