Ocean
TrackerMono.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_MONO_H
9 #define META_OCEAN_TRACKING_MAPBUILDING_TRACKER_MONO_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 TrackerMono final : public RelocalizerMono
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  TrackerMono() = default;
44 
45  /**
46  * Creates a new tracker object.
47  * @param imageFeaturePointDetectorFunction The feature detection and description function to be used
48  */
49  explicit TrackerMono(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 anyCamera The camera profile defining the projection, must be valid
60  * @param yFrame The frame with pixel format FORMAT_Y8, must be valid
61  * @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
62  * @param minimalNumberCorrespondences The minimal number of 2D/3D correspondences so that a camera pose counts as valid, with range [4, infinity)
63  * @param maximalProjectionError The maximal projection error between 3D object points and their 2D observations, in pixels, with range [0, infinity)
64  * @param world_T_roughCamera Optional rough camera pose to speedup the relocalization, if known, invalid otherwise
65  * @param worker Optional worker to distribute the computation
66  * @return True, if succeeded
67  */
68  bool track(const AnyCamera& anyCamera, const Frame& yFrame, HomogenousMatrix4& world_T_camera, const unsigned int minimalNumberCorrespondences, const Scalar maximalProjectionError, const HomogenousMatrix4& world_T_roughCamera = HomogenousMatrix4(false), Worker* worker = nullptr);
69 
70  protected:
71 
72  /**
73  * Creates the feature correspondences debugging element.
74  * @param anyCamera The camera profile defining the projection of the camera, must be valid
75  * @param world_T_camera The transformation between camera and world, must be valid
76  */
77  void createDebuggingElementFeatureCorrespondences(const AnyCamera& anyCamera, const HomogenousMatrix4& world_T_camera);
78 
79  protected:
80 
81  /// The frame pyramid holding the previous camera image.
83 
84  /// The frame pyramid holding the current camera image.
86 
87  /// The previous image points.
89 
90  /// The previous object points.
92 
93  /// The map mapping object point ids to object point indices.
95 };
96 
97 }
98 
99 }
100 
101 }
102 
103 #endif // META_OCEAN_TRACKING_MAPBUILDING_TRACKER_MONO_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:1760
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 mono cameras.
Definition: RelocalizerMono.h:33
This class implements a tracker for mono cameras.
Definition: TrackerMono.h:30
TrackerMono()=default
Creates a new tracker object.
void createDebuggingElementFeatureCorrespondences(const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera)
Creates the feature correspondences debugging element.
ObjectPointIdMap objectPointIdMap_
The map mapping object point ids to object point indices.
Definition: TrackerMono.h:94
Vectors3 previousObjectPoints_
The previous object points.
Definition: TrackerMono.h:91
bool track(const AnyCamera &anyCamera, const Frame &yFrame, HomogenousMatrix4 &world_T_camera, const unsigned int minimalNumberCorrespondences, const Scalar maximalProjectionError, const HomogenousMatrix4 &world_T_roughCamera=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: TrackerMono.h:36
bool setFeatureMap(SharedUnifiedFeatureMap featureMap) override
Sets or updates the feature map to be used for relocalization.
Vectors2 previousImagePoints_
The previous image points.
Definition: TrackerMono.h:88
CV::FramePyramid yCurrentFramePyramid_
The frame pyramid holding the current camera image.
Definition: TrackerMono.h:85
CV::FramePyramid yPreviousFramePyramid_
The frame pyramid holding the previous camera image.
Definition: TrackerMono.h:82
TrackerMono(ImageFeaturePointDetectorFunction imageFeaturePointDetectorFunction)
Creates a new tracker object.
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