Ocean
Loading...
Searching...
No Matches
TrackingCorrespondences.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_SLAM_TRACKING_CORRESPONDENCES_H
9#define META_OCEAN_TRACKING_SLAM_TRACKING_CORRESPONDENCES_H
10
15
17
20
24
25namespace Ocean
26{
27
28namespace Tracking
29{
30
31namespace SLAM
32{
33
34/**
35 * This class holds 2D-2D point correspondences for frame-to-frame tracking.
36 * The class manages image point correspondences between consecutive frames, along with associated 3D object point information for localized points.
37 * @ingroup trackingslam
38 */
39class OCEAN_TRACKING_SLAM_EXPORT TrackingCorrespondences
40{
41 public:
42
43 /// Definition of valid correspondence flags.
44 using ValidCorrespondences = std::vector<uint8_t>;
45
46 public:
47
48 /**
49 * Creates a new tracking correspondences object with reserved memory.
50 */
52
53 /**
54 * Updates the internal data structures for a new frame.
55 * This method resets previously stored information and populates the correspondences from the localized object point map and point track map.
56 * @param previousFrameIndex The index of the previous frame, with range [0, infinity)
57 * @param mapVersion The current map version
58 * @param localizedObjectPointMap The map of localized object points
59 * @param pointTrackMap The map of point tracks
60 * @param minimalFrontPrecision The minimal precision for points to be sorted to the front
61 */
62 void update(const Index32 previousFrameIndex, const Index32 mapVersion, const LocalizedObjectPointMap& localizedObjectPointMap, PointTrackMap& pointTrackMap, const LocalizedObjectPoint::LocalizationPrecision minimalFrontPrecision);
63
64 /**
65 * Optimizes the previous camera pose using the stored correspondences.
66 * @param camera The camera profile, must be valid
67 * @param world_T_previousCamera The previous camera pose to optimize, must be valid
68 * @param minimalCorrespondences The minimal number of correspondences required
69 * @param world_T_optimizedPreviousCamera The resulting optimized pose
70 * @param estimatorType The robust estimator type
71 * @param gravityConstraints Optional gravity constraints
72 * @return True if optimization succeeded
73 */
74 bool optimizePreviousCameraPose(const AnyCamera& camera, const HomogenousMatrix4& world_T_previousCamera, const size_t minimalCorrespondences, HomogenousMatrix4& world_T_optimizedPreviousCamera, const Geometry::Estimator::EstimatorType estimatorType, const Geometry::GravityConstraints* gravityConstraints) const;
75
76 /**
77 * Tracks the image points from the previous frame to the current frame.
78 * This method performs bidirectional feature tracking using the stored previous image points and populates the current image points and valid correspondence flags.
79 * @param currentFrameIndex The index of the current frame, with range [1, infinity)
80 * @param camera The camera profile, must be valid
81 * @param world_T_previousCamera The pose of the previous camera in world coordinates, invalid if unknown
82 * @param yPreviousFramePyramid The frame pyramid of the previous frame, must be valid
83 * @param yCurrentFramePyramid The frame pyramid of the current frame, must be valid and have the same frame type as the previous pyramid
84 * @param trackingParameters The tracking parameters defining pyramid configuration and patch size
85 * @param previousCamera_Q_currentCamera The rotation from the previous camera to the current camera (from IMU), invalid if unavailable
86 * @param minimalFrontPrecision The minimal precision for object points to be used for guided tracking predictions
87 */
88 void trackImagePoints(const Index32 currentFrameIndex, const AnyCamera& camera, const HomogenousMatrix4& world_T_previousCamera, const CV::FramePyramid& yPreviousFramePyramid, const CV::FramePyramid& yCurrentFramePyramid, const Tracker::TrackingParameters& trackingParameters, const Quaternion& previousCamera_Q_currentCamera, const LocalizedObjectPoint::LocalizationPrecision minimalFrontPrecision);
89
90 /**
91 * Returns the previous frame index.
92 * @return The previous frame index
93 */
94 inline Index32 previousFrameIndex() const;
95
96 /**
97 * Returns the map version.
98 * @return The map version
99 */
100 inline Index32 mapVersion() const;
101
102 /**
103 * Returns the previous image points.
104 * @return The previous image points
105 */
106 inline const Vectors2& previousImagePoints() const;
107
108 /**
109 * Returns the current image points.
110 * @return The current image points
111 */
112 inline const Vectors2& currentImagePoints() const;
113
114 /**
115 * Returns the point IDs.
116 * @return The point IDs
117 */
118 inline const Indices32& pointIds() const;
119
120 /**
121 * Returns the valid correspondences flags.
122 * @return The valid correspondences flags
123 */
124 inline const ValidCorrespondences& validCorrespondences() const;
125
126 /**
127 * Counts the number of valid correspondences.
128 * @return The number of valid correspondences
129 */
131
132 /**
133 * Returns the 3D object points for localized correspondences.
134 * @return The object points
135 */
136 inline const Vectors3& objectPoints() const;
137
138 /**
139 * Returns the localization precisions for localized correspondences.
140 * @return The localization precisions
141 */
142 inline const LocalizedObjectPoint::LocalizationPrecisions& objectPointPrecisions() const;
143
144 /**
145 * Returns the number of correspondences.
146 * @return The number of correspondences
147 */
148 inline size_t size() const;
149
150 /**
151 * Returns whether there are no correspondences.
152 * @return True if empty
153 */
154 inline bool isEmpty() const;
155
156 protected:
157
158 /// The index of the previous frame.
159 Index32 previousFrameIndex_ = Index32(-1);
160
161 /// The map version at the time the correspondences were gathered.
162 Index32 mapVersion_ = 0u;
163
164 /// The 2D image points in the previous frame.
166
167 /// The 2D image points in the current frame, one for each previous image point.
169
170 /// The unique IDs of the points, one for each previous image point.
172
173 /// Set of point ids for fast lookup, workaround for separation between localized object points and point tracks.
175
176 /// Flags indicating which correspondences are valid after tracking.
178
179 /// The 3D object points for localized correspondences.
181
182 /// The localization precisions for localized correspondences.
184
185 // TODO add whether object point has descriptor (to ensure that we can switch from TS_INITIALIZING to TS_TRACKING)
186};
187
192
194{
195 return mapVersion_;
196}
197
202
207
209{
210 return pointIds_;
211}
212
217
219{
220 return objectPoints_;
221}
222
227
228inline size_t TrackingCorrespondences::size() const
229{
230 ocean_assert(previousImagePoints_.size() == pointIds_.size());
231
232 return pointIds_.size();
233}
234
236{
237 return pointIds_.empty();
238}
239
240}
241
242}
243
244}
245
246#endif // META_OCEAN_TRACKING_SLAM_TRACKING_CORRESPONDENCES_H
This class implements the abstract base class for all AnyCamera objects.
Definition AnyCamera.h:131
This class implements a frame pyramid.
Definition FramePyramid.h:46
EstimatorType
Definition of individual robust estimator types.
Definition Estimator.h:34
This class implements a container allowing to define gravity constraints during e....
Definition GravityConstraints.h:63
LocalizationPrecision
Definition of possible localization precisions.
Definition LocalizedObjectPoint.h:59
std::vector< LocalizationPrecision > LocalizationPrecisions
Definition of a vector holding localization precisions.
Definition LocalizedObjectPoint.h:75
This class holds tracking parameters for different tracking modes.
Definition tracking/slam/Tracker.h:167
This class holds 2D-2D point correspondences for frame-to-frame tracking.
Definition TrackingCorrespondences.h:40
UnorderedIndexSet32 pointIdSet_
Set of point ids for fast lookup, workaround for separation between localized object points and point...
Definition TrackingCorrespondences.h:174
Vectors2 previousImagePoints_
The 2D image points in the previous frame.
Definition TrackingCorrespondences.h:165
const Vectors2 & currentImagePoints() const
Returns the current image points.
Definition TrackingCorrespondences.h:203
const Vectors3 & objectPoints() const
Returns the 3D object points for localized correspondences.
Definition TrackingCorrespondences.h:218
const Vectors2 & previousImagePoints() const
Returns the previous image points.
Definition TrackingCorrespondences.h:198
void trackImagePoints(const Index32 currentFrameIndex, const AnyCamera &camera, const HomogenousMatrix4 &world_T_previousCamera, const CV::FramePyramid &yPreviousFramePyramid, const CV::FramePyramid &yCurrentFramePyramid, const Tracker::TrackingParameters &trackingParameters, const Quaternion &previousCamera_Q_currentCamera, const LocalizedObjectPoint::LocalizationPrecision minimalFrontPrecision)
Tracks the image points from the previous frame to the current frame.
bool optimizePreviousCameraPose(const AnyCamera &camera, const HomogenousMatrix4 &world_T_previousCamera, const size_t minimalCorrespondences, HomogenousMatrix4 &world_T_optimizedPreviousCamera, const Geometry::Estimator::EstimatorType estimatorType, const Geometry::GravityConstraints *gravityConstraints) const
Optimizes the previous camera pose using the stored correspondences.
size_t size() const
Returns the number of correspondences.
Definition TrackingCorrespondences.h:228
Index32 previousFrameIndex() const
Returns the previous frame index.
Definition TrackingCorrespondences.h:188
LocalizedObjectPoint::LocalizationPrecisions objectPointPrecisions_
The localization precisions for localized correspondences.
Definition TrackingCorrespondences.h:183
const LocalizedObjectPoint::LocalizationPrecisions & objectPointPrecisions() const
Returns the localization precisions for localized correspondences.
Definition TrackingCorrespondences.h:223
Indices32 pointIds_
The unique IDs of the points, one for each previous image point.
Definition TrackingCorrespondences.h:171
Index32 mapVersion() const
Returns the map version.
Definition TrackingCorrespondences.h:193
TrackingCorrespondences()
Creates a new tracking correspondences object with reserved memory.
ValidCorrespondences validCorrespondences_
Flags indicating which correspondences are valid after tracking.
Definition TrackingCorrespondences.h:177
Vectors3 objectPoints_
The 3D object points for localized correspondences.
Definition TrackingCorrespondences.h:180
const ValidCorrespondences & validCorrespondences() const
Returns the valid correspondences flags.
Definition TrackingCorrespondences.h:213
void update(const Index32 previousFrameIndex, const Index32 mapVersion, const LocalizedObjectPointMap &localizedObjectPointMap, PointTrackMap &pointTrackMap, const LocalizedObjectPoint::LocalizationPrecision minimalFrontPrecision)
Updates the internal data structures for a new frame.
Index32 previousFrameIndex_
The index of the previous frame.
Definition TrackingCorrespondences.h:159
Index32 mapVersion_
The map version at the time the correspondences were gathered.
Definition TrackingCorrespondences.h:162
const Indices32 & pointIds() const
Returns the point IDs.
Definition TrackingCorrespondences.h:208
bool isEmpty() const
Returns whether there are no correspondences.
Definition TrackingCorrespondences.h:235
Vectors2 currentImagePoints_
The 2D image points in the current frame, one for each previous image point.
Definition TrackingCorrespondences.h:168
size_t countValidCorrespondences() const
Counts the number of valid correspondences.
std::vector< uint8_t > ValidCorrespondences
Definition of valid correspondence flags.
Definition TrackingCorrespondences.h:44
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
uint32_t Index32
Definition of a 32 bit index value.
Definition Base.h:84
std::unordered_set< Index32 > UnorderedIndexSet32
Definition of an unordered_set holding 32 bit indices.
Definition Base.h:126
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::unordered_map< Index32, LocalizedObjectPoint > LocalizedObjectPointMap
Definition of an unordered map mapping object point ids to localized object points.
Definition LocalizedObjectPoint.h:43
std::unordered_map< Index32, PointTrack > PointTrackMap
Definition of an unordered map mapping object point ids to point tracks.
Definition PointTrack.h:32
The namespace covering the entire Ocean framework.
Definition Accessor.h:15