8#ifndef META_OCEAN_TRACKING_SLAM_TRACKER_MONO_H
9#define META_OCEAN_TRACKING_SLAM_TRACKER_MONO_H
81 size_t frameToFrameTrackingPossible_ = 0;
84 size_t frameToFrameTrackingActual_ = 0;
87 size_t poseEstimationCorrespondences_ = 0;
96 unsigned int mapVersion_ = 0u;
199 static constexpr bool isEnabled_ =
true;
312 using TracksMap = std::unordered_map<Index32, TrackPair>;
342 bool isBundleAdjusted_ =
false;
346 using PointMap = std::unordered_map<Index32, Point>;
427 inline Index32 frameIndex()
const;
598 inline Index32 uniqueObjectPointId();
612 template <
bool tUseReadLock = true>
680 static constexpr unsigned int descriptorThreshold();
685 std::atomic<TrackerState> trackerState_ = TS_UNKNOWN;
709 unsigned int harrisThreshold_ = 0u;
745 Scalar bundleAdjustmentSqrBaseline_ = Numeric::minValue();
769 std::atomic_bool taskDetermineInitialObjectPoints_ =
false;
781 bool frameStatisticsEnabled_ =
true;
793 frameIndex_(frameIndex)
799 keyFrameIndices_(keyFrameIndices)
806 precision_(precision)
813 if constexpr (isEnabled_)
815 statistic_ = &statistic;
822 if constexpr (isEnabled_)
824 if (statistic_ !=
nullptr)
833 if constexpr (isEnabled_)
841 if constexpr (isEnabled_)
863 return CV::Detector::FREAKDescriptor32::descriptorMatchingThreshold(35u);
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
This class implements Ocean's image class.
Definition Frame.h:1879
EstimatorType
Definition of individual robust estimator types.
Definition Estimator.h:34
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
This class implements a thread.
Definition Thread.h:115
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
Index32 frameIndex() const
Returns the current frame index.
Definition CameraPoses.h:195
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
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
This class implements the base class for all SLAM trackers.
Definition tracking/slam/Tracker.h:35
This class holds information about a 3D object point for visualization purposes.
Definition slam/TrackerMono.h:318
Point()=default
Creates a default point object.
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
FrameStatistics(const Index32 frameIndex)
Creates a new frame statistics object for a specific frame.
Definition slam/TrackerMono.h:792
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
Background object:
Definition slam/TrackerMono.h:112
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.
This class implements a monocular SLAM tracker.
Definition slam/TrackerMono.h:52
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
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
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
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:
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:
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
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
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
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
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< 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
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:61
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
std::shared_mutex Mutex
Definition of a mutex supporting read and write locks.
Definition Mutex.h:78
std::unordered_map< Index32, LocalizedObjectPoint > LocalizedObjectPointMap
Definition of an unordered map mapping object point ids to localized object points.
Definition LocalizedObjectPoint.h:43
std::shared_ptr< CameraPose > SharedCameraPose
Definition of a shared pointer holding a CameraPose object.
Definition CameraPose.h:36
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