Ocean
RelocalizerMono.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_MONO_H
9 #define META_OCEAN_TRACKING_MAPBUILDING_RELOCALIZER_MONO_H
10 
13 
15 #include "ocean/base/Worker.h"
16 
17 #include "ocean/math/AnyCamera.h"
18 
19 namespace Ocean
20 {
21 
22 namespace Tracking
23 {
24 
25 namespace MapBuilding
26 {
27 
28 /**
29  * This class implements a relocalizer for mono cameras.
30  * @ingroup trackingmapbuilding
31  */
32 class OCEAN_TRACKING_MAPBUILDING_EXPORT RelocalizerMono : public Relocalizer
33 {
34  public:
35 
36  /**
37  * This class implements a container for debug elements.
38  */
40  public DebugElements,
41  public Singleton<RelocalizerDebugElements>
42  {
43  friend class Singleton<RelocalizerDebugElements>;
44 
45  public:
46 
47  /**
48  * Definition of several debug elements.
49  */
50  enum ElementId : uint32_t
51  {
52  /// An invalid element id.
53  EI_INVALID = 0u,
54 
55  /// A camera image with image features.
57 
58  /// A camera image with feature correspondences.
60  };
61  };
62 
63  public:
64 
65  /**
66  * Creates a new relocalizer object.
67  */
68  RelocalizerMono() = default;
69 
70  /**
71  * Move constructor.
72  * @param relocalizerMono The relocalizer to be moved
73  */
74  inline RelocalizerMono(RelocalizerMono&& relocalizerMono);
75 
76  /**
77  * Creates a new relocalizer object.
78  * @param imageFeaturePointDetectorFunction The feature detection and description function to be used
79  */
80  explicit RelocalizerMono(ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction);
81 
82  /**
83  * Relocalizes a given frame.
84  * @param camera The camera profile defining the projection, must be valid
85  * @param yFrame The frame with pixel format FORMAT_Y8, must be valid
86  * @param world_T_camera The resulting camera pose transforming camera to world, with default camera pose pointing towards the negative z-space and y-axis upwards
87  * @param minimalNumberCorrespondences The minimal number of 2D/3D correspondences so that a camera pose counts as valid, with range [4, infinity)
88  * @param maximalProjectionError The maximal projection error between 3D object points and their 2D observations, in pixels, with range [0, infinity)
89  * @param inlierRate The rate of correspondence inliers within the entire set of correspondences, e.g., 0.15 means that 15% of matched features are correct and can be used to determine a valid pose, with range (0, 1]
90  * @param world_T_roughCamera Optional rough camera pose to speedup the relocalization, if known, invalid otherwise
91  * @param worker Optional worker to distribute the computation
92  * @param usedObjectPointIds Optional resulting ids of the 3D object points which have been used during relocalization, nullptr if not of interest
93  * @param usedImagePoints Optional resulting 2D image points that have been used during relocalization, nullptr if not of interest
94  * @return True, if succeeded
95  */
96  bool relocalize(const AnyCamera& camera, const Frame& yFrame, HomogenousMatrix4& world_T_camera, const unsigned int minimalNumberCorrespondences, const Scalar maximalProjectionError, const Scalar inlierRate = Scalar(0.15), const HomogenousMatrix4& world_T_roughCamera = HomogenousMatrix4(false), Worker* worker = nullptr, Indices32* usedObjectPointIds = nullptr, Vectors2* usedImagePoints = nullptr);
97 
98  /**
99  * Move operator.
100  * @param relocalizerMono The relocalizer to be moved
101  * @return Reference to this object
102  */
103  inline RelocalizerMono& operator=(RelocalizerMono&& relocalizerMono);
104 };
105 
107 {
108  *this = std::move(relocalizerMono);
109 }
110 
112 {
113  Relocalizer::operator=(std::move(relocalizerMono));
114 
115  return *this;
116 }
117 
118 }
119 
120 }
121 
122 }
123 
124 #endif // META_OCEAN_TRACKING_MAPBUILDING_RELOCALIZER_MONO_H
This class implements the abstract base class for all AnyCamera objects.
Definition: AnyCamera.h:130
This class implements the base class for a container for debug elements.
Definition: DebugElements.h:29
This class implements Ocean's image class.
Definition: Frame.h:1760
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
This class base class for all relocalizers.
Definition: Relocalizer.h:31
Relocalizer & operator=(Relocalizer &&relocalizer)
Move operator.
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
This class implements a container for debug elements.
Definition: RelocalizerMono.h:42
ElementId
Definition of several debug elements.
Definition: RelocalizerMono.h:51
@ EI_CAMERA_IMAGE_WITH_FEATURES
A camera image with image features.
Definition: RelocalizerMono.h:56
@ EI_CAMERA_IMAGE_WITH_FEATURE_CORRESPONDENCES
A camera image with feature correspondences.
Definition: RelocalizerMono.h:59
This class implements a relocalizer for mono cameras.
Definition: RelocalizerMono.h:33
RelocalizerMono(ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction)
Creates a new relocalizer object.
RelocalizerMono & operator=(RelocalizerMono &&relocalizerMono)
Move operator.
Definition: RelocalizerMono.h:111
bool relocalize(const AnyCamera &camera, const Frame &yFrame, HomogenousMatrix4 &world_T_camera, const unsigned int minimalNumberCorrespondences, const Scalar maximalProjectionError, const Scalar inlierRate=Scalar(0.15), const HomogenousMatrix4 &world_T_roughCamera=HomogenousMatrix4(false), Worker *worker=nullptr, Indices32 *usedObjectPointIds=nullptr, Vectors2 *usedImagePoints=nullptr)
Relocalizes a given frame.
RelocalizerMono()=default
Creates a new relocalizer object.
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition: Vector2.h:64
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition: HomogenousMatrix4.h:37
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15