Ocean
RelocalizerStereo.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_STEREO_H
9 #define META_OCEAN_TRACKING_MAPBUILDING_RELOCALIZER_STEREO_H
10 
13 
15 #include "ocean/base/Worker.h"
16 
17 #include "ocean/cv/FramePyramid.h"
18 
19 #include "ocean/math/AnyCamera.h"
20 
21 namespace Ocean
22 {
23 
24 namespace Tracking
25 {
26 
27 namespace MapBuilding
28 {
29 
30 /**
31  * This class implements a relocalizer for stereo cameras.
32  * @ingroup trackingmapbuilding
33  */
34 class OCEAN_TRACKING_MAPBUILDING_EXPORT RelocalizerStereo : public Relocalizer
35 {
36  public:
37 
38  /**
39  * This class implements a container for debug elements.
40  */
42  public DebugElements,
43  public Singleton<RelocalizerDebugElements>
44  {
45  friend class Singleton<RelocalizerDebugElements>;
46 
47  public:
48 
49  /**
50  * Definition of several debug elements.
51  */
52  enum ElementId : uint32_t
53  {
54  /// An invalid element id.
55  EI_INVALID = 0u,
56 
57  /// A camera images with image features.
59 
60  /// A camera images with feature correspondences.
62  };
63  };
64 
65  public:
66 
67  /**
68  * Creates a new relocalizer object.
69  */
70  RelocalizerStereo() = default;
71 
72  /**
73  * Move constructor.
74  * @param relocalizerStereo The relocalizer to be moved
75  */
76  inline RelocalizerStereo(RelocalizerStereo&& relocalizerStereo);
77 
78  /**
79  * Creates a new relocalizer object.
80  * @param imageFeaturePointDetectorFunction The feature detection and description function to be used
81  */
82  explicit RelocalizerStereo(ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction);
83 
84  /**
85  * Relocalizes a given frame.
86  * @param cameraA The camera profile defining the projection of the first camera, must be valid
87  * @param cameraB The camera profile defining the projection of the second camera, must be valid
88  * @param device_T_cameraA The transformation between the first camera and the device, with default camera pose pointing towards the negative z-space and y-axis upwards, must be valid
89  * @param device_T_cameraB The transformation between the second camera and the device, with default camera pose pointing towards the negative z-space and y-axis upwards, must be valid
90  * @param yFrameA The first frame with pixel format FORMAT_Y8, must be valid
91  * @param yFrameB The second frame with pixel format FORMAT_Y8, must be valid
92  * @param world_T_device The resulting device pose transforming device to world
93  * @param minimalNumberCorrespondences The minimal number of 2D/3D correspondences so that a camera pose counts as valid, with range [4, infinity)
94  * @param maximalProjectionError The maximal projection error between 3D object points and their 2D observations, in pixels, with range [0, infinity)
95  * @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]
96  * @param world_T_roughDevice Optional rough device pose to speedup the relocalization, if known, invalid otherwise
97  * @param worker Optional worker to distribute the computation
98  * @param usedFeatureCorrespondences Optional resulting number of feature correspondences which have been used, nullptr if not of interest
99  * @param usedObjectPointIdsA Optional resulting ids of the 3D object points which have been used during relocalization in the first camera, nullptr if not of interest
100  * @param usedObjectPointIdsB Optional resulting ids of the 3D object points which have been used during relocalization in the second camera, nullptr if not of interest
101  * @param usedImagePointsA Optional resulting 2D image points that have been used during relocalization in the first camera, nullptr if not of interest
102  * @param usedImagePointsB Optional resulting 2D image points that have been used during relocalization in the second camera, nullptr if not of interest
103  * @return True, if succeeded
104  */
105  bool relocalize(const AnyCamera& cameraA, const AnyCamera& cameraB, const HomogenousMatrix4& device_T_cameraA, const HomogenousMatrix4& device_T_cameraB, const Frame& yFrameA, const Frame& yFrameB, HomogenousMatrix4& world_T_device, const unsigned int minimalNumberCorrespondences, const Scalar maximalProjectionError, const Scalar inlierRate = Scalar(0.15), const HomogenousMatrix4& world_T_roughDevice = HomogenousMatrix4(false), Worker* worker = nullptr, size_t* usedFeatureCorrespondences = nullptr, Indices32* usedObjectPointIdsA = nullptr, Indices32* usedObjectPointIdsB = nullptr, Vectors2* usedImagePointsA = nullptr, Vectors2* usedImagePointsB = nullptr);
106 
107  /**
108  * Move operator.
109  * @param relocalizerStereo The relocalizer to be moved
110  * @return Reference to this object
111  */
112  inline RelocalizerStereo& operator=(RelocalizerStereo&& relocalizerStereo);
113 };
114 
116 {
117  *this = std::move(relocalizerStereo);
118 }
119 
121 {
122  Relocalizer::operator=(std::move(relocalizerStereo));
123 
124  return *this;
125 }
126 
127 }
128 
129 }
130 
131 }
132 
133 #endif // META_OCEAN_TRACKING_MAPBUILDING_RELOCALIZER_STEREO_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: RelocalizerStereo.h:44
ElementId
Definition of several debug elements.
Definition: RelocalizerStereo.h:53
@ EI_CAMERA_IMAGES_WITH_FEATURES
A camera images with image features.
Definition: RelocalizerStereo.h:58
@ EI_CAMERA_IMAGES_WITH_FEATURE_CORRESPONDENCES
A camera images with feature correspondences.
Definition: RelocalizerStereo.h:61
This class implements a relocalizer for stereo cameras.
Definition: RelocalizerStereo.h:35
RelocalizerStereo(ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction)
Creates a new relocalizer object.
RelocalizerStereo & operator=(RelocalizerStereo &&relocalizerStereo)
Move operator.
Definition: RelocalizerStereo.h:120
bool relocalize(const AnyCamera &cameraA, const AnyCamera &cameraB, const HomogenousMatrix4 &device_T_cameraA, const HomogenousMatrix4 &device_T_cameraB, const Frame &yFrameA, const Frame &yFrameB, HomogenousMatrix4 &world_T_device, const unsigned int minimalNumberCorrespondences, const Scalar maximalProjectionError, const Scalar inlierRate=Scalar(0.15), const HomogenousMatrix4 &world_T_roughDevice=HomogenousMatrix4(false), Worker *worker=nullptr, size_t *usedFeatureCorrespondences=nullptr, Indices32 *usedObjectPointIdsA=nullptr, Indices32 *usedObjectPointIdsB=nullptr, Vectors2 *usedImagePointsA=nullptr, Vectors2 *usedImagePointsB=nullptr)
Relocalizes a given frame.
RelocalizerStereo()=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