Ocean
Unified.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_TRACKING_MAPBUILDING_UNIFIED_H
9 #define META_OCEAN_TRACKING_MAPBUILDING_UNIFIED_H
10 
17 
19 #include "ocean/base/Worker.h"
20 
21 #include "ocean/geometry/Octree.h"
22 
23 #include "ocean/math/AnyCamera.h"
25 #include "ocean/math/Vector2.h"
26 #include "ocean/math/Vector3.h"
27 
30 
31 namespace Ocean
32 {
33 
34 namespace Tracking
35 {
36 
37 namespace MapBuilding
38 {
39 
40 /**
41  * This is the base class for all descriptor extractors.
42  * @ingroup trackingmapbuilding
43  */
45 {
46  public:
47 
48  /**
49  * Destructs the object.
50  */
51  virtual ~UnifiedDescriptorExtractor() = default;
52 
53  /**
54  * Determines the descriptor for a given image point and adds the descriptor to the map for the corresponding object point.
55  * @param yFramePyramid The image pyramid from which the feature point will be extracted, must be valid
56  * @param anyCamera The camera profile defining the projection, must be valid
57  * @param imagePoint The 2D image point of the feature point
58  * @param objectPointId The id of the object point to which the descriptor will be added, must be valid
59  * @param unifiedDescriptorMap The unified descriptor map to which the descriptor will be added
60  * @return True, if succeeded
61  */
62  virtual bool createAndAddDescriptor(const CV::FramePyramid& yFramePyramid, const AnyCamera& anyCamera, const Vector2& imagePoint, const Index32& objectPointId, UnifiedDescriptorMap& unifiedDescriptorMap) const = 0;
63 
64  /**
65  * Creates a new descriptor map for this extractor.
66  * @return The new descriptor map
67  */
68  virtual std::shared_ptr<UnifiedDescriptorMap> createUnifiedDescriptorMap() const = 0;
69 };
70 
71 /**
72  * This class implements the descriptor extractor for FREAK Multi descriptors with 32 bytes or 256 bits.
73  * @ingroup trackingmapbuilding
74  */
75 class OCEAN_TRACKING_MAPBUILDING_EXPORT UnifiedDescriptorExtractorFreakMultiDescriptor256 : public UnifiedDescriptorExtractor
76 {
77  public:
78 
79  /**
80  * Determines the descriptor for a given image point and adds the descriptor to the map for the corresponding object point.
81  * @see UnifiedDescriptorExtractor::createAndAddDescriptor().
82  */
83  bool createAndAddDescriptor(const CV::FramePyramid& yFramePyramid, const AnyCamera& anyCamera, const Vector2& imagePoint, const Index32& objectPointId, UnifiedDescriptorMap& unifiedDescriptorMap) const override;
84 
85  /**
86  * Creates a new descriptor map for this extractor.
87  * @return The new descriptor map
88  */
89  std::shared_ptr<UnifiedDescriptorMap> createUnifiedDescriptorMap() const override;
90 };
91 
92 /**
93  * This class implements a helper class for FREAK Multi descriptors with 32 bytes or 256 bits.
94  * @ingroup trackingmapbuilding
95  */
96 class OCEAN_TRACKING_MAPBUILDING_EXPORT UnifiedHelperFreakMultiDescriptor256 : public DescriptorHandling
97 {
98  public:
99 
100  /// The binary descriptor.
102 
103  /// The binary descriptors.
105 
106  /// Definition of the distance value.
107  typedef unsigned int BinaryDescriptorDistance;
108 
109  /// Definition of a vocabulary forest.
111 
112  /// Definition of a vocabulary tree.
114 
115  /// Definition of a descriptor for object points.
117 
118  /**
119  * Initializes the data structures for guided and unguided matching.
120  * @param objectPoints The 3D object points for matching, may be adjusted internally
121  * @param objectPointIds The ids of the 3D object points, one for each object point, may be adjusted internally
122  * @param descriptorMap The map mapping object point ids to their corresponding descriptors
123  * @param randomGenerator The random generator to be used
124  * @param objectPointDescriptors The resulting descriptors for the 3D object points
125  * @param objectPointIndices The indices of the corresponding 3D object points, one for each object point descriptor, mainly a map mapping descriptor indices to point indices, must be valid
126  * @param objectPointDescriptorsForest The resulting forest with object point descriptors
127  * @param objectPointOctree The resulting octree for the 3D object points
128  * @return @return True, if succeeded
129  */
130  static bool initialize(Vectors3& objectPoints, Indices32& objectPointIds, const UnifiedDescriptorMap& descriptorMap, RandomGenerator& randomGenerator, BinaryDescriptors256& objectPointDescriptors, Indices32& objectPointIndices, BinaryVocabularyForest& objectPointDescriptorsForest, Geometry::Octree& objectPointOctree);
131 
132  /**
133  * Initializes the data structures for guided and unguided matching.
134  * @param database The database holding the topology of the features
135  * @param descriptorMap The map mapping object point ids to their corresponding descriptors
136  * @param randomGenerator The random generator to be used
137  * @param objectPoints The resulting 3D object points
138  * @param objectPointIds The resulting ids of the 3D object points, one for each object point
139  * @param objectPointDescriptors The resulting descriptors for the 3D object points
140  * @param objectPointIndices The indices of the corresponding 3D object points, one for each object point descriptor, mainly a map mapping descriptor indices to point indices, must be valid
141  * @param objectPointDescriptorsForest The resulting forest with object point descriptors
142  * @param objectPointOctree The resulting octree for the 3D object points
143  * @return @return True, if succeeded
144  */
145  static bool initialize(const Tracking::Database& database, const UnifiedDescriptorMap& descriptorMap, RandomGenerator& randomGenerator, Vectors3& objectPoints, Indices32& objectPointIds, BinaryDescriptors256& objectPointDescriptors, Indices32& objectPointIndices, BinaryVocabularyForest& objectPointDescriptorsForest, Geometry::Octree& objectPointOctree);
146 
147  /**
148  * Initializes the data structures for guided and unguided matching.
149  * @param database The database holding the topology of the features
150  * @param descriptorMap The map mapping object point ids to their corresponding descriptors
151  * @param randomGenerator The random generator to be used
152  * @param objectPoints The resulting 3D object points
153  * @param objectPointIds The resulting ids of the 3D object points, one for each object point
154  * @param objectPointDescriptors The resulting descriptors for the 3D object points
155  * @param objectPointIndices The indices of the corresponding 3D object points, one for each object point descriptor, mainly a map mapping descriptor indices to point indices, must be valid
156  * @param objectPointDescriptorsForest The resulting forest with object point descriptors
157  * @param objectPointOctree The resulting octree for the 3D object points
158  * @param unifiedUnguidedMatching The resulting unified unguided matching object
159  * @param unifiedGuidedMatching The resulting unified guided matching object
160  * @return @return True, if succeeded
161  */
162  static bool initialize(const Tracking::Database& database, const UnifiedDescriptorMap& descriptorMap, RandomGenerator& randomGenerator, Vectors3& objectPoints, Indices32& objectPointIds, BinaryDescriptors256& objectPointDescriptors, Indices32& objectPointIndices, BinaryVocabularyForest& objectPointDescriptorsForest, Geometry::Octree& objectPointOctree, std::unique_ptr<UnifiedUnguidedMatchingFreakMultiFeatures256Group>& unifiedUnguidedMatching, std::unique_ptr<UnifiedGuidedMatchingFreakMultiDescriptor256Group>& unifiedGuidedMatching);
163 
164  /**
165  * Extracts vocabulary descriptors from a descriptor feature map.
166  * This function mainly serializes the descriptors from the map and e.g., separates multi-level/multi-layer descriptors into individual descriptors.
167  * @param descriptorMap The descriptor map containing the features to serialize
168  * @param objectPoints The resulting 3D object points
169  * @param objectPointIds The resulting ids of all 3D object points
170  * @param objectPointIndices The resulting indices of 3D object points, allowing to map extracted vocabulary descriptors to object points (e.g., because the given object point descriptor may be multi-level or/and multi-view descriptors
171  * @param vocabularyDescriptors The resulting descriptors for the vocabulary tree, must be single-view, single-level descriptors
172  */
173  static bool extractVocabularyDescriptorsFromMap(const UnifiedDescriptorMap& descriptorMap, Vectors3& objectPoints, Indices32& objectPointIds, Indices32& objectPointIndices, UnifiedDescriptor::ByteDescriptors<32u>& vocabularyDescriptors);
174 };
175 
176 /**
177  * This class implements a helper class for float descriptors.
178  * @ingroup trackingmapbuilding
179  */
180 class OCEAN_TRACKING_MAPBUILDING_EXPORT UnifiedHelperFloatSingleLevelMultiView128
181 {
182  public:
183 
184  /**
185  * Extracts vocabulary descriptors from a descriptor feature map.
186  * This function mainly serializes the descriptors from the map and e.g., separates multi-level/multi-layer descriptors into individual descriptors.
187  * @param descriptorMap The descriptor map containing the features to serialize
188  * @param objectPoints The resulting 3D object points
189  * @param objectPointIds The resulting ids of all 3D object points
190  * @param objectPointIndices The resulting indices of 3D object points, allowing to map extracted vocabulary descriptors to object points (e.g., because the given object point descriptor may be multi-level or/and multi-view descriptors
191  * @param vocabularyDescriptors The resulting descriptors for the vocabulary tree, must be single-view, single-level descriptors
192  */
193  static bool extractVocabularyDescriptorsFromMap(const UnifiedDescriptorMap& descriptorMap, Vectors3& objectPoints, Indices32& objectPointIds, Indices32& objectPointIndices, UnifiedDescriptor::FloatDescriptors<128u>& vocabularyDescriptors);
194 };
195 
196 }
197 
198 }
199 
200 }
201 
202 #endif // META_OCEAN_TRACKING_MAPBUILDING_POSE_ESTIMATION_H
This class implements the abstract base class for all AnyCamera objects.
Definition: AnyCamera.h:130
This class implements a frame pyramid.
Definition: FramePyramid.h:37
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
This class implements a database for 3D object points, 2D image points and 6DOF camera poses.
Definition: Database.h:67
This class implements functions necessary when handling descriptors.
Definition: DescriptorHandling.h:32
This class implements the descriptor extractor for FREAK Multi descriptors with 32 bytes or 256 bits.
Definition: Unified.h:76
std::shared_ptr< UnifiedDescriptorMap > createUnifiedDescriptorMap() const override
Creates a new descriptor map for this extractor.
bool createAndAddDescriptor(const CV::FramePyramid &yFramePyramid, const AnyCamera &anyCamera, const Vector2 &imagePoint, const Index32 &objectPointId, UnifiedDescriptorMap &unifiedDescriptorMap) const override
Determines the descriptor for a given image point and adds the descriptor to the map for the correspo...
This is the base class for all descriptor extractors.
Definition: Unified.h:45
virtual std::shared_ptr< UnifiedDescriptorMap > createUnifiedDescriptorMap() const =0
Creates a new descriptor map for this extractor.
virtual bool createAndAddDescriptor(const CV::FramePyramid &yFramePyramid, const AnyCamera &anyCamera, const Vector2 &imagePoint, const Index32 &objectPointId, UnifiedDescriptorMap &unifiedDescriptorMap) const =0
Determines the descriptor for a given image point and adds the descriptor to the map for the correspo...
virtual ~UnifiedDescriptorExtractor()=default
Destructs the object.
std::vector< FloatDescriptor< tNumberElements > > FloatDescriptors
Definition of a vector holding float descriptors.
Definition: UnifiedDescriptor.h:147
std::vector< BinaryDescriptor< tNumberBits > > BinaryDescriptors
Definition of a vector holding binary descriptors.
Definition: UnifiedDescriptor.h:133
std::vector< ByteDescriptor< tNumberBytes > > ByteDescriptors
Definition of a vector holding byte descriptors.
Definition: UnifiedDescriptor.h:119
ByteDescriptor< tNumberBits/8u > BinaryDescriptor
Definition of a binary descriptor.
Definition: UnifiedDescriptor.h:126
This class implements the base class for all unified descriptor maps in which ids are mapped to descr...
Definition: UnifiedDescriptorMap.h:38
This class implements a helper class for float descriptors.
Definition: Unified.h:181
static bool extractVocabularyDescriptorsFromMap(const UnifiedDescriptorMap &descriptorMap, Vectors3 &objectPoints, Indices32 &objectPointIds, Indices32 &objectPointIndices, UnifiedDescriptor::FloatDescriptors< 128u > &vocabularyDescriptors)
Extracts vocabulary descriptors from a descriptor feature map.
This class implements a helper class for FREAK Multi descriptors with 32 bytes or 256 bits.
Definition: Unified.h:97
CV::Detector::FREAKDescriptors32 ObjectPointDescriptor
Definition of a descriptor for object points.
Definition: Unified.h:116
BinaryVocabularyForest::TVocabularyTree BinaryVocabularyTree
Definition of a vocabulary tree.
Definition: Unified.h:113
Tracking::VocabularyForest< BinaryDescriptor256, BinaryDescriptorDistance, UnifiedDescriptorT< BinaryDescriptor256 >::determineDistance > BinaryVocabularyForest
Definition of a vocabulary forest.
Definition: Unified.h:110
static bool initialize(Vectors3 &objectPoints, Indices32 &objectPointIds, const UnifiedDescriptorMap &descriptorMap, RandomGenerator &randomGenerator, BinaryDescriptors256 &objectPointDescriptors, Indices32 &objectPointIndices, BinaryVocabularyForest &objectPointDescriptorsForest, Geometry::Octree &objectPointOctree)
Initializes the data structures for guided and unguided matching.
UnifiedDescriptor::BinaryDescriptors< 256u > BinaryDescriptors256
The binary descriptors.
Definition: Unified.h:104
static bool initialize(const Tracking::Database &database, const UnifiedDescriptorMap &descriptorMap, RandomGenerator &randomGenerator, Vectors3 &objectPoints, Indices32 &objectPointIds, BinaryDescriptors256 &objectPointDescriptors, Indices32 &objectPointIndices, BinaryVocabularyForest &objectPointDescriptorsForest, Geometry::Octree &objectPointOctree)
Initializes the data structures for guided and unguided matching.
static bool extractVocabularyDescriptorsFromMap(const UnifiedDescriptorMap &descriptorMap, Vectors3 &objectPoints, Indices32 &objectPointIds, Indices32 &objectPointIndices, UnifiedDescriptor::ByteDescriptors< 32u > &vocabularyDescriptors)
Extracts vocabulary descriptors from a descriptor feature map.
static bool initialize(const Tracking::Database &database, const UnifiedDescriptorMap &descriptorMap, RandomGenerator &randomGenerator, Vectors3 &objectPoints, Indices32 &objectPointIds, BinaryDescriptors256 &objectPointDescriptors, Indices32 &objectPointIndices, BinaryVocabularyForest &objectPointDescriptorsForest, Geometry::Octree &objectPointOctree, std::unique_ptr< UnifiedUnguidedMatchingFreakMultiFeatures256Group > &unifiedUnguidedMatching, std::unique_ptr< UnifiedGuidedMatchingFreakMultiDescriptor256Group > &unifiedGuidedMatching)
Initializes the data structures for guided and unguided matching.
UnifiedDescriptor::BinaryDescriptor< 256u > BinaryDescriptor256
The binary descriptor.
Definition: Unified.h:101
unsigned int BinaryDescriptorDistance
Definition of the distance value.
Definition: Unified.h:107
This class implements a Vocabulary Forest holding several Vocabulary Trees.
Definition: VocabularyTree.h:766
This class implements a Vocabulary Tree for feature descriptors.
Definition: VocabularyTree.h:223
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
uint32_t Index32
Definition of a 32 bit index value.
Definition: Base.h:84
OctreeT< Scalar > Octree
Definition of an Octree using Scalar as data type.
Definition: Octree.h:25
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition: Vector3.h:65
std::vector< FREAKDescriptor32 > FREAKDescriptors32
Vector of 32-bytes long FREAK descriptors.
Definition: FREAKDescriptor.h:69
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15