Ocean
TrackerStereo.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_TRACKER_STEREO_H
9 #define META_OCEAN_TRACKING_MAPBUILDING_TRACKER_STEREO_H
10 
13 
14 #include "ocean/cv/FramePyramid.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Tracking
20 {
21 
22 namespace MapBuilding
23 {
24 
25 /**
26  * This class implements a tracker for mono cameras.
27  * @ingroup trackingmapbuilding
28  */
29 class OCEAN_TRACKING_MAPBUILDING_EXPORT TrackerStereo final : public RelocalizerStereo
30 {
31  protected:
32 
33  /**
34  * Definition of an unordered map mapping object point ids to object point indices.
35  */
36  typedef std::unordered_map<Index32, Index32> ObjectPointIdMap;
37 
38  public:
39 
40  /**
41  * Creates a new tracker object.
42  */
43  TrackerStereo() = default;
44 
45  /**
46  * Creates a new tracker object.
47  * @param imageFeaturePointDetectorFunction The feature detection and description function to be used
48  */
49  explicit TrackerStereo(ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction);
50 
51  /**
52  * Sets or updates the feature map to be used for relocalization.
53  * @see Relocalizer::setFeatureMap().
54  */
55  bool setFeatureMap(SharedUnifiedFeatureMap featureMap) override;
56 
57  /**
58  * Tracks the current frame a given frame.
59  * @param anyCameraA The camera profile defining the projection of the first camera, must be valid
60  * @param anyCameraB The camera profile defining the projection of the second camera, must be valid
61  * @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
62  * @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
63  * @param yFrameA The first frame with pixel format FORMAT_Y8, must be valid
64  * @param yFrameB The second frame with pixel format FORMAT_Y8, must be valid
65  * @param world_T_device The resulting device pose transforming device to world
66  * @param minimalNumberCorrespondences The minimal number of 2D/3D correspondences so that a camera pose counts as valid, with range [4, infinity)
67  * @param maximalProjectionError The maximal projection error between 3D object points and their 2D observations, in pixels, with range [0, infinity)
68  * @param world_T_roughDevice Optional rough device pose to speedup the relocalization, if known, invalid otherwise
69  * @param worker Optional worker to distribute the computation
70  * @return True, if succeeded
71  */
72  bool track(const AnyCamera& anyCameraA, const AnyCamera& anyCameraB, 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 HomogenousMatrix4& world_T_roughDevice = HomogenousMatrix4(false), Worker* worker = nullptr);
73 
74  protected:
75 
76  /**
77  * Creates the feature correspondences debugging element.
78  * @param anyCameraA The camera profile defining the projection of the first camera, must be valid
79  * @param anyCameraB The camera profile defining the projection of the second camera, must be valid
80  * @param world_T_device The transformation between device and world, must be valid
81  * @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
82  * @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
83  */
84  void createDebuggingElementFeatureCorrespondences(const AnyCamera& anyCameraA, const AnyCamera& anyCameraB, const HomogenousMatrix4& world_T_device, const HomogenousMatrix4& device_T_cameraA, const HomogenousMatrix4& device_T_cameraB);
85 
86  protected:
87 
88  /// The frame pyramid holding the previous first camera image.
90 
91  /// The frame pyramid holding the previous second camera image.
93 
94  /// The frame pyramid holding the current first camera image.
96 
97  /// The frame pyramid holding the current second camera image.
99 
100  /// The previous image points in the first camera.
102 
103  /// The previous image points in the second camera.
105 
106  /// The previous object points observed in the first camera.
108 
109  /// The previous object points observed in the second camera.
111 
112  /// The map mapping object point ids to object point indices.
114 };
115 
116 }
117 
118 }
119 
120 }
121 
122 #endif // META_OCEAN_TRACKING_MAPBUILDING_TRACKER_STEREO_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 Ocean's image class.
Definition: Frame.h:1792
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 relocalizer for stereo cameras.
Definition: RelocalizerStereo.h:35
This class implements a tracker for mono cameras.
Definition: TrackerStereo.h:30
Vectors2 previousImagePointsA_
The previous image points in the first camera.
Definition: TrackerStereo.h:101
CV::FramePyramid yPreviousFramePyramidA_
The frame pyramid holding the previous first camera image.
Definition: TrackerStereo.h:89
CV::FramePyramid yCurrentFramePyramidA_
The frame pyramid holding the current first camera image.
Definition: TrackerStereo.h:95
bool setFeatureMap(SharedUnifiedFeatureMap featureMap) override
Sets or updates the feature map to be used for relocalization.
bool track(const AnyCamera &anyCameraA, const AnyCamera &anyCameraB, 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 HomogenousMatrix4 &world_T_roughDevice=HomogenousMatrix4(false), Worker *worker=nullptr)
Tracks the current frame a given frame.
std::unordered_map< Index32, Index32 > ObjectPointIdMap
Definition of an unordered map mapping object point ids to object point indices.
Definition: TrackerStereo.h:36
Vectors2 previousImagePointsB_
The previous image points in the second camera.
Definition: TrackerStereo.h:104
CV::FramePyramid yPreviousFramePyramidB_
The frame pyramid holding the previous second camera image.
Definition: TrackerStereo.h:92
TrackerStereo(ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction)
Creates a new tracker object.
void createDebuggingElementFeatureCorrespondences(const AnyCamera &anyCameraA, const AnyCamera &anyCameraB, const HomogenousMatrix4 &world_T_device, const HomogenousMatrix4 &device_T_cameraA, const HomogenousMatrix4 &device_T_cameraB)
Creates the feature correspondences debugging element.
TrackerStereo()=default
Creates a new tracker object.
Vectors3 previousObjectPointsA_
The previous object points observed in the first camera.
Definition: TrackerStereo.h:107
CV::FramePyramid yCurrentFramePyramidB_
The frame pyramid holding the current second camera image.
Definition: TrackerStereo.h:98
Vectors3 previousObjectPointsB_
The previous object points observed in the second camera.
Definition: TrackerStereo.h:110
ObjectPointIdMap objectPointIdMap_
The map mapping object point ids to object point indices.
Definition: TrackerStereo.h:113
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
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
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
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15