Contenido principal

How to Improve Accuracy in Visual SLAM

R2026b

Achieving reliable real-time localization and mapping is essential for robotics and AR applications. Computer Vision Toolbox™ provides a performant, configurable, and easy-to-use interface that offers an out-of-the-box solution for visual simultaneous localization and mapping (vSLAM), handling tasks such as feature extraction, matching, pose estimation, mapping, loop closure, and IMU sensor fusion internally. To meet performance demands, you can improve the accuracy, robustness, and efficiency of your visual SLAM system by optimizing sensor use for loop closure and tuning key parameters. For a general description on what SLAM is and how it works for different applications, see What is SLAM?

Using Verbose Mode to Diagnose SLAM Errors

During SLAM processing, you can diagnose and troubleshoot errors using runtime messages returned to the command line as the algorithm runs. To display these messages, set the Verbose property of your monovslam, stereovslam, or rgbdvslam object to 1.

Progress information display, specified as [], 1, 2, or 3. Paths to the location of log files, when they are created, is displayed on the command line.

Verbose ValueDisplay DescriptionDisplay Location
[] or falseDisplay is turned offNone
1 or trueStages of vSLAM executionMATLAB® Command Window
2Stages of vSLAM execution, with details on how the frame is processed, such as the artifacts used to initialize the map. The MATLAB Command Window displays a link to the log file.
3Stages of vSLAM, artifacts used to initialize the map, poses and map points before and after bundle adjustment, and loop closure optimization data.The MATLAB Command Window displays a link to the log file.

This table lists some of the most common messages and root causes you might encounter and some of their possible root causes.

Verbose MessageRoot CauseParameters to Tune

  • Not enough matched points with frame {K}. NumMatchedPoints=X is less than MinNumPoints=Y

  • Not enough feature points in frame {K}. NumMatchedPoints=X is less than MinExtractedPoints=Y

  • Not enough world points in frame {K}. NumWorldPoints=X is less than MinWorldPoints=Y

If, the count of tracked features or points falls below a critical threshold, this can result in initialization failures or a loss of tracking. Factors that can contribute to this include: inadequate image quality, abrupt variations in brightness, or rapid movements.

To mitigate this problem, consider extracting a larger number of 2-D features, or reduce the number of frames skipped between each pair of keyframes.

  • MaxNumPoints

  • ScaleFactor

  • NumLevels

  • SkipMaxFrames

See SLAM Initialization and Tune Keyframe and Tracking Parameters.

Loop not closed. All loop candidates were rejected

Loop closure failures typically arise from these primary factors:

  • The loop closure threshold might be set too high, resulting in missed matches. Gradually lower this threshold to enhance your results, but note that setting it too low can lead to false positives.

  • The bag of words utilized might not be well-suited to the input data.

When other methods do not yield sufficient performance, consider generating a new bag-of-words model using data from a camera sensor with characteristics similar to the target sensor.

  • LoopClosureThreshold

  • CustomBagOfFeatures

See Loop Closure.

Tracking lost

Loss of tracking can occur due to these factors:

  • An insufficient number of extracted features, which can result in a gradual decline in the number of tracked features.

  • An excessive number of frames skipped between each pair of keyframes, particularly in sequences involving aggressive maneuvers.

  • A threshold that is set too high for the minimum number of tracked features.

Use checkStatus for diagnostic feedback. For more details, see Tracking and Keyframe Management.

  • MaxNumPoints

  • SkipMaxFrames

  • TrackFeatureRange

See Tune Keyframe and Tracking Parameters.

In addition to enabling Verbose mode, see Techniques to Improve Accuracy for common sources of inaccuracy and ways to improve SLAM accuracy.

Sources of Inaccuracy in SLAM

Achieving high accuracy in visual SLAM is challenging because errors can arise from many sources. Issues with sensor calibration, data association, or environmental complexity can all lead to drift or inaccurate maps. Understanding where these inaccuracies originate is the first step toward improving system performance. Factors that can affect the accuracy of SLAM systems include:

  • Camera Calibration — Inaccurate camera calibration, such as errors in intrinsic parameters, can lead to incorrect pose estimation and mapping results.

  • SLAM Initialization — Issues during initialization. If the system cannot extract or reliably match enough visual features between initial frames, it might struggle to track motion or build a consistent map.

  • Tracking and Keyframe Management — You can lose tracking due to factors such as motion blur, fast camera movements, or scenes with few distinctive visual features.

  • Loop Closure — A missed loop closure can occur if the system either fails to recognize that it has revisited a location (a false negative) or erroneously identifies a loop closure (a false positive). In both cases, the system might not property correct accumulated errors in its position estimate.

  • Visual-Inertial SLAM (Sensor Fusion) — Poor sensor fusion between camera and IMU data in SLAM often results from IMU calibration and incorrect noise models.

Techniques to Improve Accuracy

To improve SLAM accuracy, you must optimize several key components of the system. Optimization includes techniques such as camera calibration, initialization, tracking and keyframe management, loop closure, and visual-inertial sensor fusion, each contributing to more reliable and precise mapping and localization.

Camera Calibration Accuracy

Accurate camera calibration in SLAM ensures precise mapping of 3-D environments and reliable pose estimation. A camera calibration is accurate when the reprojection error is low, typically below one pixel, and remains evenly distributed across all images. Undistorting images that contain straight lines should preserve their straightness, with no bending or structured artifacts. The calibration should also perform reliably in downstream tasks, such as pose estimation or SLAM, and should not introduce curvature, drift, or scale inconsistencies.

Camera intrinsic parameters describe how a camera projects 3-D world points onto a 2-D image plane, including focal length, principal point, and lens distortion coefficients. Accurate intrinsic parameters are critical for 3-D reconstruction, visual SLAM, and image distortion.

To improve calibration accuracy, capture enough high-quality images to provide diverse views and full image coverage of a calibration pattern. For image capture guidelines, see Data Collection Guidelines for Single-Camera Calibration.

To compute camera intrinsic parameters, you can use the Camera Calibrator app or the estimateCameraParameters function.

Image quality directly affects the accuracy of SLAM and other feature-based computer vision tasks. Lens distortion can bend straight lines and bias feature detection, reducing geometric consistency across images. To improve image quality and downstream accuracy, undistort images using the camera parameters obtained from calibration. Image undistortion removes lens distortion and preserves scene geometry, enabling feature detection and matching with corrected images.

Use the undistortImage function with the distorted image and the cameraParameters object to generate an undistorted image. This correction ensures that straight lines in the real world appear straight in the image.

A distorted image of a checkerboard, in which the borders of the checkerboard and lines between squares are curved, and the undistorted image of the same checkerboard is undistorted.

Fisheye images introduce strong lens distortion that can reduce feature tracking accuracy and geometric consistency. To improve SLAM accuracy and compatibility, convert fisheye images to a standard pinhole model using the undistortFisheyeImage function with parameters estimated from fisheye calibration. This conversion generates new intrinsic parameters corresponding to the equivalent pinhole camera model. Providing these undistorted images and updated parameters to the monovslam object ensures compatibility with algorithms designed for pinhole cameras while maintaining accurate feature detection and tracking.

For more details about fisheye calibration, see Fisheye Calibration Basics.

A fisheye distorted image and the same image undistorted to a pinhole camera perspective.

SLAM Initialization

SLAM initialization establishes the first reference frame and creates the initial 3-D map of the environment. During this phase, the system detects and matches visual features to estimate the camera pose and the positions of scene keypoints. A good initialization means that the position of the camera is stable and does not jump around unexpectedly. It also requires a nondegenerate baseline between the first keyframes, which means the camera must move enough so that you can clearly estimate the 3-D structure of the scene. In addition, you want the points in the map to be well-triangulated, with positive depth and enough parallax for accurate reconstruction. If you can track the first few frames reliably, and the map does not quickly collapse, change shape, or scale incorrectly, then the initialization is sufficient for normal SLAM operation to continue.

The initialization process differs primarily based on how depth information is obtained:

  • Monocular SLAM — Depth must be inferred from motion. The system analyzes feature correspondences across several frames to estimate relative depth through parallax. This process introduces scale ambiguity, meaning the map is created up to an unknown scale until additional data (such as from an IMU or a known object size in the scene) resolves it. Parallax, the apparent shift in the position of objects when the camera moves sideways, is essential for estimating depth and constructing an accurate map. During initialization, insufficient camera motion can reduce parallax, making it difficult to estimate depth reliably. These early errors can persist throughout the mapping process, affecting overall accuracy.

  • Stereo or RGB-D SLAM — These systems have immediate access to metric depth information, either through disparity computation (stereo) or a depth sensor (RGB-D), enabling initialization with absolute scale and improved robustness.

The initialization stage relies heavily on feature extraction and matching to estimate the initial camera pose and the 3-D positions of keypoints. Image resolution directly affects this process by determining how many distinctive features you can detect and match across frames. For stable and efficient initialization, you must find a balance between feature richness and processing speed.

Use an image resolution between 640-by-480 (SD) and 1920-by-1080 (HD) and adjust the tuning parameters accordingly. You can adjust these tuning parameters by using the MaxNumPoints, ScaleFactor, and NumLevels properties of your monovslam, stereovslam, or rgbdvslam object.

  • MaxNumPoints — Controls the number of ORB keypoints extracted from each frame. Higher values improve map density and matching reliability, but result in more computations.

  • ScaleFactor — Determines the scale step between pyramid levels during feature extraction. Smaller values produce more pyramid levels, increasing scale invariance and matching robustness at the cost of speed.

  • NumLevels — Defines the number of pyramid levels for feature detection. More levels improve robustness to scale changes, but result in more computations.

These are the recommended MaxNumPoints values for various resolutions:

ResolutionMaxNumPoints ValueCharacteristics

Low (~640-by-480)

1000
  • Fewer, less distinctive features

  • Fast processing, but low robustness

Medium (~1280-by-720)

2000
  • Moderate feature density and distinctiveness

  • Balanced accuracy and speed

High (~1080-by-1920)

2000 – 3000
  • Rich, detailed features

  • Slower initialization due to greater number of computations

These images show the tuning of ScaleFactor and NumLevels and their effect on the total number of matches and run time. Run time can vary based on your hardware configuration.

For stereo visual SLAM, initialization relies on accurate disparity estimation between the left and right camera images to reconstruct depth from pixel correspondences. The DisparityRange property of the stereovslam object, defined as a two-element vector of the form [minDisparity maxDisparity], defines the valid pixel range used during this stereo matching process.

Because the disparity range directly affects both the quality of depth reconstruction and the computational efficiency of the initialization process, a poorly chosen range can have negative impacts:

  • Range too narrow — Valid depth points are lost, resulting in incomplete or noisy map reconstruction.

  • Range too wide — Computational cost increases and false correspondences might occur, reducing map accuracy.

Select a range that fully spans the expected depth variation of your environment. For guidance on choosing appropriate values, see Choosing Range of Disparity.

Tracking and Keyframe Management

Tracking and keyframe management are critical components of SLAM systems. Tracking estimates the motion of the camera over time, while keyframes are selected frames that capture significant changes in viewpoint and serve as stable reference points to maintain map consistency and support robust localization. The methods for managing tracking and keyframes are described in these techniques:

In monocular visual SLAM, tracking continuously estimates the camera pose by detecting and matching visual features between the current frame and the existing keyframes. This process enables the system to localize the camera, decide when to add new keyframes, and update the map with newly observed features.

Stable tracking depends on maintaining a sufficient number of reliable feature correspondences across frames. If you lose tracking, mapping stops and you might need to perform relocalization. Tracking behavior and keyframe selection are primarily controlled by the SkipMaxFrames and TrackFeatureRange properties of the monovslam, stereovslam, and rgbdvslam objects.

  • SkipMaxFrames — Defines the maximum number of frames that can be skipped before forcing a new keyframe. Use lower values for sequences with fast or irregular motion. If a video has been recorded at less than 30 FPS, or has already been downsampled, then consider reducing the value of SkipMaxFrames.

    Frame Rate or Motion ScenarioSkipMaxFrames ValuesCharacteristics
    Slow or static motion~20Skips more frames between keyframes to improve speed when motion is minimal. Safe for static or slow sequences. Excessive skipping during motion can cause drift.
    Moderate motion or handheld10–15Balances performance and robustness. Maintains consistent localization with manageable computational load.
    Fast or abrupt motion5–10Reduces skipped frames to maintain robustness during rapid camera movement. Increases computational load, but prevents tracking failure.
  • TrackFeatureRange — Specifies the lower and upper limits for the number of tracked points required for keyframe creation. Helps control the rate of new keyframe insertion. The lower limit should be in the range [30, 50]. The upper limit should be approximately 15% of the value of the MaxNumPoints property of the same object.

The checkStatus function provides diagnostic feedback during runtime, indicating the health of the tracking process. Use these messages to identify issues such as insufficient feature matches or complete tracking loss, and adjust parameters like MaxNumPoints, SkipMaxFrames, or feature extraction settings as necessary.

checkStatus Output FieldDefinitionRecommended Action
TrackingLost

Too few reliable correspondences exist. The number of tracked feature points in the current frame is below the lower limit set by TrackFeatureRange. This indicates the image does not contain enough features, or that the camera is moving too fast.

One or both of these actions:

  • Increase the upper limit value of TrackFeatureRange,

  • Decrease the SkipMaxFrames value to add key frames more frequently.

TrackingSuccessful

Tracking is successful. The number of tracked feature points in the current frame is between the lower and upper limits set by TrackFeatureRange.

Continue mapping.
FrequentKeyFrames

Tracking adds key frames too frequently. The number of tracked feature points exceeds the upper bound of TrackFeatureRange.

Consider increasing the lower limit of TrackFeatureRange so keyframes are not inserted as frequently, or reduce MaxNumPoints to limit feature density.

Loop Closure

Loop closure is a process in SLAM that detects when the camera revisits a previously mapped area. By recognizing these revisits, the system can correct accumulated drift and refine both the trajectory and the map, ensuring consistency. Loop closure typically runs in the background using feature-based place recognition, matching visual features from the current view against those from past keyframes. Effective loop closure significantly improves the accuracy and robustness of SLAM in large or repeatedly traversed environments.

You can use these properties of the monovslam, stereovslam, and rgbdvslam objects to tune loop closure:

  • LoopClosureThreshold — Sets the similarity threshold for confirming a loop closure between keyframes.

  • CustomBagOfFeatures — Custom bag of words (BoW) vocabulary for loop closure detection. Using this argument requires a pretrained BoW vocabulary.

PropertyPurposeSensitivityBest Practice

CustomBagOfFeatures

Define a custom bag of words (BoW) vocabulary to improve place recognition during loop closure.Using an untrained or generic vocabulary can cause missed matches or false positives, especially in scenes with repetitive textures or unique lighting.Train a BoW vocabulary on representative images from the target environment using the bagOfFeaturesDBoW object (based on the DBoW2 library). A well-trained vocabulary improves loop closure detection reliability and reduces false matches.
LoopClosureThresholdSet the similarity score threshold for confirming a loop closure candidate.If set too high, the system might miss valid loop closures. If set too low, it increases the risk of incorrect matches and map distortion.Start with the default threshold, then adjust it by increasing the value in feature-rich environments to reduce false positives, or decreasing it in low-texture scenes to avoid missed closures. When increasing MaxNumPoints, raise this threshold proportionally.

Visual-Inertial SLAM (Sensor Fusion)

Visual-inertial SLAM uses both camera and IMU data to improve motion tracking. By combining these measurements, the system stays accurate even during rapid motion or challenging visual conditions, where feature extraction degrades. These key techniques enable you to leverage IMU data and optimize its integration:

Incorporating IMU data into SLAM improves robustness by providing continuous motion information, which helps maintain accurate tracking during rapid movements or in texture-poor environments, that produce blurry images. IMU measurements supply accelerations and angular velocities at high rates, filling gaps between camera frames and compensating for visual ambiguities.

Visual-inertial SLAM (VI-SLAM) combines camera and IMU data to achieve robust localization and mapping, even in challenging environments. The fusion of visual camera and inertial IMU sensor data provides scale information, stabilizes tracking, and improves accuracy during fast motion or visual degradation. Achieving precise results requires careful calibration, parameter tuning, and initialization.

To enable visual-inertial fusion, you must configure a factorIMUParameters (Navigation Toolbox) object that stores IMU-specific parameters such as the sampling rate, sensor noise characteristics, and biases for both the accelerometer and gyroscope. These parameters are typically provided by the IMU sensor manufacturer. However, if these values are not available, you can estimate them using Allan variance analysis with the allanvar (Navigation Toolbox) function. For an example that uses this function, see Inertial Sensor Noise Analysis Using Allan Variance (Navigation Toolbox).

Note that the monovslam object expects, IMU noise values as covariances rather than standard deviations. If the manufacturer provides random walk standard deviations (or if you obtain them from Allan variance analysis), square them to convert them to covariances. This differs from some open-source frameworks, which typically use standard deviations.

For example, if the gyroscope random walk is 10–4, then:

GyroscopeBiasNoise = (10–4)2 = 1e–8

You must specify all IMU fusion properties in the correct units:

  • GyroscopeBiasNoise — (rad/s)2

  • AccelerometerBiasNoise — (m/s2)2

  • GyroscopeNoise — (rad/s)2

  • AccelerometerNoise — (m/s2)2

A well-tuned IMU parameter set improves sensor fusion accuracy, reduces drift, and ensures consistent pose estimation across long sequences.

IMU initialization in monocular visual-inertial SLAM involves estimating both gravity rotation and pose scale. These steps are essential to resolve the scale ambiguity inherent in monocular vision and to align inertial and visual data within a consistent reference frame.

  • Gravity rotation — The gravity rotation estimation aligns the inertial measurements with the visual data, ensuring the orientation of the system reflects the true gravitational direction. This alignment is essential for accurate motion estimation because accelerometer readings include the constant acceleration due to gravity, which does not represent actual motion and must be removed before sensor fusion.

    Since the input pose reference frame might not match the IMU local navigation frame, typically north–east–down (NED) or east–north–up (ENU), in which you know the gravity direction, you must to transform the estimated camera poses to the local navigation frame to remove the known gravity effect. The estimated rotation provides this transformation, aligning the input pose reference frame to the IMU local navigation reference frame.

    The monovslam object stores the estimated gravity alignment has returned in the GravityRotation property. When this alignment is successfully estimated, the IsIMUAligned property value is true.

  • Pose scale — Estimation determines the real-world metric scale of the scene, enabling accurate and drift-free 3-D reconstruction and trajectory estimation.

    For monocular systems, estimating the pose scale is necessary because you cannot directly infer the real-world scale of the scene from images alone. By leveraging inertial data, the system can resolve this scale ambiguity, resulting in more accurate and reliable mapping and localization.

    The monovslam object stores the estimated scale factor in the IsIMUAligned property.

Together, the gravity rotation and pose scale estimations enable the system to produce metrically accurate 3-D reconstructions and trajectories. Note that camera-IMU fusion cannot proceed if the IMU initialization is not successful.

This animation illustrates the effects of properly tuning the gravity rotation and pose scale estimations by showing the SLAM trajectory before and after alignment. Once the estimation has been applied, the trajectory plot automatically updates to reflect the path in the newly aligned reference frame, incorporating the corrected (estimated) scale. This ensures that the visualized trajectory is both spatially accurate and metrically consistent with the real-world environment.

Animation showing the before and after alignment effects of tuning the gravity rotation and pose scale estimations.

The monovslam, stereovslam, and rgbdvslam SLAM objects automatically estimate gravity rotation and pose scale using internally designed factor graphs. With sufficient data coverage and appropriate tuning of the NumPosesThreshold and AlignmentThreshold properties, you can achieve reliable initialization with minimal user intervention.

Best Practices for Successful Camera-IMU Alignment:

You typically perform gravity rotation and pose scale estimation early in the sequence, once a sufficient number of camera poses have been collected. For more information on this calibration technique, see Gravity Rotation and Pose Scale (Navigation Toolbox).

To obtain a reliable estimation of gravity rotation and pose scale, the collected poses should satisfy these conditions:

  • Number of poses — Try to keep the number of poses under 30 for most cameras and frame rates. A larger number increases drift, while fewer than 10 poses might not provide enough information for a robust estimation.

  • Motion diversity — Include rotation around all three axes.

  • Vertical translation — Incorporate upward motion (opposite the gravity direction).

  • Pose accuracy — Ensure accurate camera pose estimates by tuning SLAM object properties, such as TrackFeatureRange or SkipMaxFrames.

The NumPosesThreshold and AlignmentFraction properties control the number of camera poses used for camera-IMU alignment. These settings determine when the alignment process begins and how much of the available data is used, respectively.

To perform accurate calibration between the camera and IMU, you must collect a sufficient number of camera-only poses. The NumPosesThreshold defines the minimum number of camera poses required before alignment can begin, while AlignmentFraction determines the proportion of the total data set to use during the alignment process.

These properties help ensure that enough spatial and temporal information is available to reliably align the camera and IMU data streams.

  • NumPosesThreshold — Number of estimated camera poses required to trigger IMU alignment. Too few poses results in unstable estimates; too many can incorporate drift. Try to keep the number of poses under 30 for most cameras and frame rates. A larger number increases drift, while fewer than 10 poses might not provide enough information for a robust estimation.

  • AlignmentFraction — Subset of the most recent poses used for alignment, specified as a scalar in the range (0, 1]. This range helps exclude early noisy estimates for more accurate calibration. The number of poses considered for alignment is:

    round(NumPosesThreshold*AlignmentFraction).

    This value effectively filters out initial, potentially noisy pose estimates, ensuring only the most relevant data contributes to the alignment for improved accuracy.

Key Takeaways for Improving SLAM Accuracy

Achieving robust and accurate SLAM depends on careful tuning and validation. After setting parameters for camera calibration, initialization, tracking, loop closure, and IMU fusion, validate your system by visualizing trajectories, checking for drift, and confirming that loop closures and IMU alignment occur consistently. To compare estimated trajectories against ground truth, you can use the compareTrajectories function.

Use the diagnostic messages, mapping visualizations, and performance metrics to identify weak points in the processing of your data and environment. Adjust parameters as needed until tracking remains stable under varying motion, lighting, and environmental conditions.

Improving SLAM accuracy is an iterative process that combines precise sensor calibration, thoughtful parameter tuning, and validation against real-world data. By systematically refining your configuration and verifying performance using the visualization and diagnostic tools in Computer Vision Toolbox and Navigation Toolbox™, you can achieve high-accuracy, real-time SLAM suitable for robotics, AR, and autonomous navigation applications.

See Also

Topics