8#ifndef META_OCEAN_TRACKING_SLAM_TRACKER_MONO_H
9#define META_OCEAN_TRACKING_SLAM_TRACKER_MONO_H
312 using TracksMap = std::unordered_map<Index32, TrackPair>;
346 using PointMap = std::unordered_map<Index32, Point>;
612 template <
bool tUseReadLock = true>
static constexpr unsigned int descriptorMatchingThreshold(const unsigned int percent)
This class implements a frame pyramid.
Definition FramePyramid.h:46
This class implements Ocean's image class.
Definition Frame.h:1969
EstimatorType
Definition of individual robust estimator types.
Definition Estimator.h:34
static constexpr Scalar minValue()
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
This class implements a calculate for rates like frame rates.
Definition RateCalculator.h:25
Thread(const std::string &name=std::string())
Creates a new thread object.
This class implements a task which runs in the background while the caller is able to wait for the ta...
Definition BackgroundTask.h:48
This class holds the camera pose of a camera in relation to the world.
Definition CameraPose.h:46
This class implements a container for camera poses.
Definition CameraPoses.h:32
This class implements a scoped pyramid object providing automatic lifetime management.
Definition FramePyramidManager.h:41
This class manages a pool of frame pyramids for efficient reuse.
Definition FramePyramidManager.h:33
This class implements a container for gravity vectors associated with frame indices.
Definition Gravities.h:29
This class implements a thread-safe container for object point ids.
Definition LocalizedObjectPoint.h:155
LocalizationPrecision
Definition of possible localization precisions.
Definition LocalizedObjectPoint.h:59
@ LP_LOW
The localization precision is low, because the object point has not been observed from enough differe...
Definition LocalizedObjectPoint.h:65
@ LP_INVALID
An invalid localization precision.
Definition LocalizedObjectPoint.h:61
This class implements an occupancy array allowing to keep track of occupied and unoccupied bins in a ...
Definition OccupancyArray.h:32
This class holds 2D-3D point correspondences for camera pose estimation.
Definition PoseCorrespondences.h:39
This class implements a configuration object for the tracker.
Definition tracking/slam/Tracker.h:56
This class holds tracking parameters for different tracking modes.
Definition tracking/slam/Tracker.h:167
Tracker()=default
Creates a new tracker object.
@ TS_UNKNOWN
The tracker is in an unknown state (e.g., not yet started).
Definition tracking/slam/Tracker.h:44
Point()=default
Creates a default point object.
Vector3 position_
The 3D position of the object point.
Definition slam/TrackerMono.h:336
bool isBundleAdjusted_
True if this object point has been optimized by Bundle Adjustment.
Definition slam/TrackerMono.h:342
LocalizedObjectPoint::LocalizationPrecision precision_
The localization precision of the object point.
Definition slam/TrackerMono.h:339
This class holds debug data for visualization and analysis purposes.
Definition slam/TrackerMono.h:305
void update(DebugData &&debugData)
Updates the debug data by merging from another DebugData object.
std::pair< Index32, Vectors2 > TrackPair
Definition of a pair combining the last frame index with a sequence of 2D image points.
Definition slam/TrackerMono.h:309
std::unordered_map< Index32, TrackPair > TracksMap
Definition of a map mapping object point ids to their track data.
Definition slam/TrackerMono.h:312
std::unordered_map< Index32, Point > PointMap
Definition of a map mapping object point ids to their 3D positions and precisions.
Definition slam/TrackerMono.h:346
TracksMap tracksMap_
The map of 2D point tracks, mapping object point ids to their last frame index and sequence of 2D obs...
Definition slam/TrackerMono.h:376
UnorderedIndexSet32 poseNotPreciseObjectPointIds_
The set of object point ids with imprecise localization used for pose estimation.
Definition slam/TrackerMono.h:385
UnorderedIndexSet32 inaccurateObjectPointIdSet_
The set of object point ids that were identified as outliers during pose estimation.
Definition slam/TrackerMono.h:388
PointMap pointMap_
The map of 3D object points, mapping object point ids to their 3D positions and localization precisio...
Definition slam/TrackerMono.h:379
UnorderedIndexSet32 posePreciseObjectPointIds_
The set of object point ids with precise localization used for pose estimation.
Definition slam/TrackerMono.h:382
void clear()
Clears all debug data.
void update(const Index32 frameIndex, const TrackingCorrespondences &trackingCorrespondences, const PoseCorrespondences &poseCorrespondences)
Updates the tracking data with new frame correspondences.
This class holds per-frame tracking statistics for debugging and analysis.
Definition slam/TrackerMono.h:60
size_t frameToFrameTrackingActual_
The number of feature points that were actually tracked successfully from the previous frame.
Definition slam/TrackerMono.h:84
Index32 frameIndex_
The index of the frame these statistics belong to.
Definition slam/TrackerMono.h:78
size_t frameToFrameTrackingPossible_
The number of feature points that could potentially be tracked from the previous frame.
Definition slam/TrackerMono.h:81
FrameStatistics(const Index32 frameIndex)
Creates a new frame statistics object for a specific frame.
Definition slam/TrackerMono.h:792
Scalar projectionError_
The average projection error of the estimated pose, negative if not computed.
Definition slam/TrackerMono.h:90
size_t poseEstimationCorrespondences_
The number of 2D-3D correspondences used for pose estimation.
Definition slam/TrackerMono.h:87
unsigned int mapVersion_
The map version at the time of pose estimation.
Definition slam/TrackerMono.h:96
HomogenousMatrix4 world_T_camera_
The estimated camera pose, invalid if pose estimation failed.
Definition slam/TrackerMono.h:93
bool isValid() const
Returns whether the frame statistics contain valid data.
This class holds data for a single object point to be optimized.
Definition slam/TrackerMono.h:119
Vector3 objectPoint_
The 3D position of the object point.
Definition slam/TrackerMono.h:123
std::vector< size_t > keyFrameSubsetIndices_
The indices into the keyframe subset where this object point is observed.
Definition slam/TrackerMono.h:126
Vectors2 imagePoints_
The 2D image point observations corresponding to keyFrameSubsetIndices_.
Definition slam/TrackerMono.h:129
const Indices32 & keyFrameIndices_
Reference to the keyframe indices to consider for optimization.
Definition slam/TrackerMono.h:168
void collectObjectPoints(const LocalizedObjectPointMap &localizedObjectPointMap, const UnorderedIndexSet32 &previousBundleAdjustmentObjectPointIdSet)
Collects object points that are visible in at least one keyframe and were not part of the previous Bu...
std::unordered_map< Index32, OptimizationObject > OptimizationObjectMap
Definition of a map mapping object point ids to their optimization data.
Definition slam/TrackerMono.h:133
ObjectPointOptimization(const Indices32 &keyFrameIndices)
Creates a new object point optimization object.
Definition slam/TrackerMono.h:798
OptimizationObjectMap optimizationObjectMap_
The map of object points to be optimized.
Definition slam/TrackerMono.h:171
void optimizeObjectPointsIF(const AnyCamera &camera, const HomogenousMatrices4 &optimizedFlippedCameras_T_world, const Geometry::Estimator::EstimatorType estimatorType, const Scalar maximalProjectionError, UnorderedIndexSet32 ¤tBundleAdjustmentObjectPointIdSet, Indices32 ¤tObjectPointIds, Vectors3 ¤tObjectPointPositions, Indices32 &inaccurateObjectPointIds)
Optimizes the collected object points using non-linear optimization with fixed camera poses.
PointTrackMap pointTrackMap_
The map of 2D point tracks, mapping object point ids to their tracked 2D observations across frames.
Definition slam/TrackerMono.h:697
bool relocalize(const AnyCamera &camera, const Index32 latestFrameIndex, const CV::FramePyramid &yFramePyramid)
Background function:
void matchLocalizedObjectPointsToCorners(const AnyCamera &camera, const Index32 currentFrameIndex, const CameraPose &cameraPose, const CV::FramePyramid &yFramePyramid)
Post-processing function:
FramePyramidManager::ScopedPyramid previousPyramid_
The frame pyramid of the previous frame used for frame-to-frame feature tracking.
Definition slam/TrackerMono.h:712
TrackingParameters trackingParameters_
The tracking parameters defining pyramid configuration for feature tracking.
Definition slam/TrackerMono.h:691
void bundleAdjustment(const AnyCamera &camera, const Index32 currentFrameIndex)
Background function:
bool configure(const Configuration &configuration)
Configures the tracker with the specified settings.
FramesStatistics framesStatistics() const
Returns the collected per-frame statistics.
SharedCameraPose trackImagePointsAndDeterminePose(const AnyCamera &camera, const Index32 currentFrameIndex, RandomGenerator &randomGenerator, const Quaternion &previousCamera_Q_currentCamera)
Tracks image points from the previous frame to the current frame and determines the camera pose.
bool handleFrame(const AnyCamera &camera, Frame &&yFrame, HomogenousMatrix4 &world_T_camera, const Vector3 &cameraGravity=Vector3(0, 0, 0), const Quaternion &anyWorld_Q_camera=Quaternion(false), DebugData *debugData=nullptr)
Processes a new camera frame and determines the camera pose.
OccupancyArray occupancyArray_
The occupancy array for spatial distribution of feature points across the image.
Definition slam/TrackerMono.h:694
void resetLocalizedObjectPoints()
Resets all localized 3D object points and related state during re-initialization.
void threadRun() override
The main loop of the background processing thread.
bool needsFrameStatistics(const Index32 frameIndex, FrameStatistics *&frameStatistics)
Checks whether frame statistics collection is enabled and retrieves a pointer to the statistics for t...
Index32 frameIndex() const
Returns the index of the current frame which the tracker has just processed.
Definition slam/TrackerMono.h:847
Scalar bundleAdjustmentSqrBaseline_
The squared baseline (camera translation distance) from the most recent Bundle Adjustment,...
Definition slam/TrackerMono.h:745
static constexpr unsigned int descriptorThreshold()
Returns the maximal distance between two descriptors so that they are considered a match (35% of desc...
Definition slam/TrackerMono.h:861
bool frameStatisticsEnabled_
True to enable collecting per-frame statistics; false to disable.
Definition slam/TrackerMono.h:781
void processTrackingResults(const Index32 currentFrameIndex, const TrackingCorrespondences &trackingCorrespondences)
Post-processing function:
CameraPoses cameraPoses_
The history of camera poses for all processed frames.
Definition slam/TrackerMono.h:727
TrackerMono()
Creates a new tracker object.
UnorderedIndexSet32 bundleAdjustmentObjectPointIdSet_
The ids of object points which have been used during the previous Bundle Adjustment.
Definition slam/TrackerMono.h:748
Mutex mutex_
The mutex for synchronizing access to shared data between foreground and background threads.
Definition slam/TrackerMono.h:766
Indices32 bundleAdjustmentKeyFrameIndices_
The frame indices of keyframes used in the most recent Bundle Adjustment.
Definition slam/TrackerMono.h:742
Index32 objectPointIdCounter_
The counter for generating unique object point ids.
Definition slam/TrackerMono.h:703
static constexpr LocalizedObjectPoint::LocalizationPrecision minimalFrontPrecision_
The minimal localization precision for projecting object points; points below this threshold use the ...
Definition slam/TrackerMono.h:778
Configuration configuration_
The configuration of the tracker.
Definition slam/TrackerMono.h:688
void updateInaccurateObjectPoints(const AnyCamera &camera, const Index32 currentFrameIndex, const UnorderedIndexSet32 &inaccurateObjectPointIdSet)
Background function:
unsigned int harrisThreshold_
The adaptive Harris corner detection threshold, adjusted dynamically based on feature coverage.
Definition slam/TrackerMono.h:709
void describeObjectPoints(const AnyCamera &camera, const Index32 currentFrameIndex, const CV::FramePyramid &yFramePyramid)
Background function:
PerformanceStatistics performanceStatistics_
The performance statistics for this tracker.
Definition slam/TrackerMono.h:751
void postHandleFrame()
Post-processing function:
FramePyramidManager framePyramidManager_
The manager for frame pyramids providing thread-safe access to image pyramids for foreground and back...
Definition slam/TrackerMono.h:706
~TrackerMono() override
Destructs this tracker object.
LocalizedObjectPointMap localizedObjectPointMap_
The map of localized 3D object points, mapping object point ids to their 3D positions and observation...
Definition slam/TrackerMono.h:700
PoseCorrespondences poseCorrespondences_
Pose estimation correspondences.
Definition slam/TrackerMono.h:724
std::pair< Index32, Vector3 > ObjectPointIdPositionPair
Definition of a pair combining object point ids and object point positions.
Definition slam/TrackerMono.h:290
void matchCornersToLocalizedObjectPoints(const AnyCamera &camera, const Index32 currentFrameIndex, const CameraPose &cameraPose, const CV::FramePyramid &yFramePyramid, CV::Detector::HarrisCorners &corners)
Post-processing function:
std::atomic_bool taskDetermineInitialObjectPoints_
True, if the background thread needs to determine initial object points. Only the foreground thread c...
Definition slam/TrackerMono.h:769
Index32 poseEstimationFailedFrameIndex_
The index of the frame in which post estimation failed the first time, -1 if a valid pose is known.
Definition slam/TrackerMono.h:772
static Index32 frameIndexWithMostLocalizedObjectPoints(const Index32 necessaryDataVersion, const CameraPoses &cameraPoses, const LocalizedObjectPointMap &localizedObjectPointMap, const size_t minimalNumberObjectPoints, const UnorderedIndexSet32 *ignoreFrameIndices=nullptr)
Determines the frame index with the most visible localized object points.
std::vector< FrameStatistics > FramesStatistics
Definition of a vector holding frame statistics.
Definition slam/TrackerMono.h:100
std::string performance() const
Returns a string with performance statistics for the tracker.
bool isBundleAdjustmentNeeded(const AnyCamera &camera, const CameraPose ¤tCameraPose, const Index32 currentFrameIndex, const Scalar maximalProjectionError, const unsigned int necessaryMapVersion) const
Background function:
std::unordered_map< Index32, PoseIndexToImagePointPairs > ObjectPointToObservations
Definition of an unordered map mapping object point ids to observation pairs.
Definition slam/TrackerMono.h:187
bool detectNewImagePoints(const AnyCamera &camera, const Index32 currentFrameIndex, const CV::FramePyramid &yFramePyramid, const bool tryMatchCornersToLocalizedObjectPoints)
Post-processing function:
SharedAnyCamera camera_
The camera profile used for projection, cloned from the first frame's camera.
Definition slam/TrackerMono.h:733
std::atomic< TrackerState > trackerState_
The current operational state of the tracker, modified only by the foreground thread but read by both...
Definition slam/TrackerMono.h:685
TrackingCorrespondences trackingCorrespondences_
Frame-to-frame tracking correspondences.
Definition slam/TrackerMono.h:721
static bool determineBundleAdjustmentTopology(const Index32 necessaryDataVersion, const CameraPoses &cameraPoses, const LocalizedObjectPointMap &localizedObjectPointMap, const size_t maximalNumberNewKeyFrames, const size_t maximalNumberKeyFrames, Indices32 &keyFrameIndices, ObjectPointToObservations &objectPointToObservations, const size_t minimalNumberKeyFrames=3, const size_t maximalFrameHistory=300)
Background function:
FramesStatistics framesStatistics_
The collected statistics for each processed frame.
Definition slam/TrackerMono.h:784
RandomGenerator randomGenerator_
The random generator for the foreground thread.
Definition slam/TrackerMono.h:736
BackgroundTask postHandleFrameTask_
The background task which will execute the post processing for the handleFrame() function.
Definition slam/TrackerMono.h:757
Gravities gravities_
The history of gravity vectors in camera coordinates for processed frames.
Definition slam/TrackerMono.h:730
void localizeUnlocalizedObjectPoints(const AnyCamera &camera, const Index32 currentFrameIndex)
Background function:
Index32 uniqueObjectPointId()
Post-processing function:
Definition slam/TrackerMono.h:852
Quaternion anyWorld_Q_previousCamera_
The orientation of the previous camera in an external/arbitrary world coordinate system (e....
Definition slam/TrackerMono.h:718
ObjectPointIdPositionPairs reusableObjectPointIdPositionPairs_
Reusable pairs of object point ids and object point positions, used in updateInaccurateObjectPoints()...
Definition slam/TrackerMono.h:789
bool determineInitialObjectPoints(const AnyCamera &camera, const Index32 latestFrameIndex, RandomGenerator &randomGenerator)
Background function:
void determineCameraPoses(const AnyCamera &camera, const Index32 startFrameIndex, const Index32 skipFrameIndex=Index32(-1), const bool stopAtValidPose=false)
Background function:
FramePyramidManager::ScopedPyramid currentPyramid_
The frame pyramid of the current frame used for frame-to-frame feature tracking.
Definition slam/TrackerMono.h:715
std::vector< PoseIndexToImagePointPair > PoseIndexToImagePointPairs
Definition of a vector holding pairs of frame indices and 2D observations.
Definition slam/TrackerMono.h:182
LocalizedObjectPoint::ObjectPointIdSet inaccurateObjectPointIdSet_
The set of object point ids whose 3D positions are considered inaccurate and need re-optimization.
Definition slam/TrackerMono.h:754
RateCalculator handleFrameRateCalculator_
The rate calculator for measuring the frame processing rate.
Definition slam/TrackerMono.h:760
DebugData debugData_
The debug data for visualization and analysis purposes.
Definition slam/TrackerMono.h:763
Index32 mapVersion_
The version counter for the map, incremented after each Bundle Adjustment to track pose and object po...
Definition slam/TrackerMono.h:775
std::pair< unsigned int, Vector2 > PoseIndexToImagePointPair
Definition of a pair combining a frame index with a 2D observation.
Definition slam/TrackerMono.h:177
RandomGenerator randomGeneratorBackground_
The random generator for the background thread.
Definition slam/TrackerMono.h:739
std::vector< ObjectPointIdPositionPair > ObjectPointIdPositionPairs
Definition of a vector holding object point id and position pairs.
Definition slam/TrackerMono.h:295
This class holds 2D-2D point correspondences for frame-to-frame tracking.
Definition TrackingCorrespondences.h:40
static VectorT3< Scalar > minValue()
uint32_t Index32
Definition of a 32 bit index value.
Definition Base.h:84
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
std::unordered_set< Index32 > UnorderedIndexSet32
Definition of an unordered_set holding 32 bit indices.
Definition Base.h:126
std::vector< HarrisCorner > HarrisCorners
Definition of a vector holding Harris corners.
Definition HarrisCorner.h:30
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
QuaternionT< Scalar > Quaternion
Definition of the Quaternion object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sin...
Definition Quaternion.h:40
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition HomogenousMatrix4.h:44
AnyCameraT< Scalar > AnyCamera
Definition of an AnyCamera object with Scalar precision.
Definition AnyCamera.h:31
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:61
VectorT3< Scalar > Vector3
Definition of a 3D vector.
Definition Vector3.h:29
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition HomogenousMatrix4.h:73
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::unordered_map< Index32, PointTrack > PointTrackMap
Definition of an unordered map mapping object point ids to point tracks.
Definition PointTrack.h:32
std::shared_mutex Mutex
Definition of a mutex supporting read and write locks.
Definition Mutex.h:78
std::shared_ptr< CameraPose > SharedCameraPose
Definition of a shared pointer holding a CameraPose object.
Definition CameraPose.h:36
std::unordered_map< Index32, LocalizedObjectPoint > LocalizedObjectPointMap
Definition of an unordered map mapping object point ids to localized object points.
Definition LocalizedObjectPoint.h:43
Namespace of the SLAM Tracking library.
Definition BackgroundTask.h:24
Namespace of the Tracker library.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15