Ocean
Relocalizer.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_RELOCALIZER_H
9 #define META_OCEAN_TRACKING_MAPBUILDING_RELOCALIZER_H
10 
14 
15 #include <functional>
16 
17 namespace Ocean
18 {
19 
20 namespace Tracking
21 {
22 
23 namespace MapBuilding
24 {
25 
26 /**
27  * This class base class for all relocalizers.
28  * @ingroup trackingmapbuilding
29  */
30 class OCEAN_TRACKING_MAPBUILDING_EXPORT Relocalizer
31 {
32  public:
33 
34  /**
35  * Definition of a function which detects and describes feature points in a given image.
36  * @param camera The camera profile associated with the image
37  * @param yFrame The image in which the feature will be detected, with pixel format FORMAT_Y8
38  * @param imagePoints The resulting image points within the pixel domain
39  * @param imagePointDescriptors The resulting descriptors, one for each resulting image point
40  * @return True, if succeeded
41  */
42  using ImageFeaturePointDetectorFunction = std::function<bool(const AnyCamera& camera, const Frame& yFrame, Vectors2& imagePoints, SharedUnifiedDescriptors& imagePointDescriptors)>;
43 
44  public:
45 
46  /**
47  * Destructs this relocalizer.
48  */
49  virtual ~Relocalizer() = default;
50 
51  /**
52  * Sets or updates the function to detect and describe feature points in an image.
53  * @param imageFeaturePointDetectorFunction The function to be used
54  * @return True, if succeeded
55  */
56  virtual bool setImageFeaturePointDetectorFunction(ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction);
57 
58  /**
59  * Sets or updates the feature map to be used for relocalization.
60  * @param featureMap The feature map to be set, must be valid
61  * @return True, if succeeded
62  */
63  virtual bool setFeatureMap(SharedUnifiedFeatureMap featureMap);
64 
65  /**
66  * Returns the object points of this relocalizer.
67  * This function is not thread-safe.
68  * @return The relocalizer's 3D object points
69  */
70  inline const Vectors3& objectPoints() const;
71 
72  /**
73  * Returns the ids of the object points of this relocalizer.
74  * This function is not thread-safe.
75  * @return The relocalizer's object point ids
76  */
77  inline const Indices32& objectPointIds() const;
78 
79  /**
80  * Returns whether this relocalizer holds a valid map.
81  * @return True, if so
82  */
83  virtual bool isValid() const;
84 
85  /**
86  * Helper function allowing to detect and to describe multi-level FREAK features with 32 bytes per descriptor in an image.
87  * @param camera The camera profile to be used, must be valid
88  * @param yFrame The image in which the feature will be detected and described, with pixel format FORMAT_Y8, must be valid
89  * @param imagePoints The resulting image points of all detected features
90  * @param imagePointDescriptors The resulting descriptors, one for each resulting image point
91  * @return True, if succeeded
92  */
93  static bool detectFreakFeatures(const AnyCamera& camera, const Frame& yFrame, Vectors2& imagePoints, SharedUnifiedDescriptors& imagePointDescriptors);
94 
95  protected:
96 
97  /**
98  * Default constructor.
99  */
100  Relocalizer() = default;
101 
102  /**
103  * Creates a new relocalizer object.
104  * @param imageFeaturePointDetectorFunction The feature detection and description function to be used
105  */
106  explicit Relocalizer(ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction);
107 
108  /**
109  * Move operator.
110  * @param relocalizer The relocalizer to be moved
111  * @return Reference to this object
112  */
114 
115  protected:
116 
117  /// The function which detects and describes feature points in a given image.
119 
120  /// The feature map to be used when relocalizing.
122 
123  /// The random generator object to be used.
125 
126  /// The relocalizer's lock.
127  mutable Lock lock_;
128 };
129 
130 inline const Vectors3& Relocalizer::objectPoints() const
131 {
132  ocean_assert(isValid());
133 
134  return featureMap_->objectPoints();
135 }
136 
138 {
139  ocean_assert(isValid());
140 
141  return featureMap_->objectPointIds();
142 }
143 
144 }
145 
146 }
147 
148 }
149 
150 #endif // META_OCEAN_TRACKING_MAPBUILDING_RELOCALIZER_H
This class implements the abstract base class for all AnyCamera objects.
Definition: AnyCamera.h:130
This class implements Ocean's image class.
Definition: Frame.h:1760
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
This class base class for all relocalizers.
Definition: Relocalizer.h:31
virtual bool setImageFeaturePointDetectorFunction(ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction)
Sets or updates the function to detect and describe feature points in an image.
ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction_
The function which detects and describes feature points in a given image.
Definition: Relocalizer.h:118
virtual ~Relocalizer()=default
Destructs this relocalizer.
Relocalizer & operator=(Relocalizer &&relocalizer)
Move operator.
Lock lock_
The relocalizer's lock.
Definition: Relocalizer.h:127
RandomGenerator randomGenerator_
The random generator object to be used.
Definition: Relocalizer.h:124
static bool detectFreakFeatures(const AnyCamera &camera, const Frame &yFrame, Vectors2 &imagePoints, SharedUnifiedDescriptors &imagePointDescriptors)
Helper function allowing to detect and to describe multi-level FREAK features with 32 bytes per descr...
virtual bool setFeatureMap(SharedUnifiedFeatureMap featureMap)
Sets or updates the feature map to be used for relocalization.
Relocalizer()=default
Default constructor.
const Vectors3 & objectPoints() const
Returns the object points of this relocalizer.
Definition: Relocalizer.h:130
const Indices32 & objectPointIds() const
Returns the ids of the object points of this relocalizer.
Definition: Relocalizer.h:137
std::function< bool(const AnyCamera &camera, const Frame &yFrame, Vectors2 &imagePoints, SharedUnifiedDescriptors &imagePointDescriptors)> ImageFeaturePointDetectorFunction
Definition of a function which detects and describes feature points in a given image.
Definition: Relocalizer.h:42
SharedUnifiedFeatureMap featureMap_
The feature map to be used when relocalizing.
Definition: Relocalizer.h:121
Relocalizer(ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction)
Creates a new relocalizer object.
virtual bool isValid() const
Returns whether this relocalizer holds a valid map.
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition: Vector2.h:64
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition: Vector3.h:65
std::shared_ptr< UnifiedFeatureMap > SharedUnifiedFeatureMap
Definition of a shared pointer holding a UnifiedFeatureMap object.
Definition: UnifiedFeatureMap.h:31
std::shared_ptr< UnifiedDescriptors > SharedUnifiedDescriptors
Definition of a shared pointer holding a UnifiedDescriptors object.
Definition: UnifiedDescriptors.h:63
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15