Skip to content

Crash when left image has very few or no features extracted in stereo mode #991

@Octweiyi

Description

@Octweiyi

Bug Description

The program crashes immediately when calling GrabImageStereo() if the left image has very few or no features extracted (e.g., nearly black image or low-texture scene).

Root Cause

In Frame::Frame() constructor for stereo cameras (line 101-134 in src/Frame.cc), when mvKeys.empty() is true, the function returns early without completing necessary initialization. This leaves critical static member variables uninitialized:

  • mfGridElementWidthInv and mfGridElementHeightInv remain uninitialized
  • mbInitialComputations stays true
  • Camera parameters (fx, fy, cx, cy, etc.) are not set

Subsequent code that accesses these uninitialized variables (e.g., GetFeaturesInArea(), PosInGrid()) causes undefined behavior and crashes.

Steps to Reproduce

  1. Run ORB-SLAM3 in stereo mode
  2. Feed a left image with very few features (e.g., nearly black image, uniform texture, or very dark scene)
  3. Call System::TrackStereo() or Tracking::GrabImageStereo()
  4. Program crashes immediately

Expected Behavior

The system should gracefully handle frames with insufficient features:

  • Complete initialization even when no features are extracted
  • Skip the frame and wait for the next frame with sufficient features
  • Continue running without crashing

Actual Behavior

Program crashes with segmentation fault or undefined behavior when accessing uninitialized grid variables.

Proposed Fix

Initialize critical variables before early return when mvKeys.empty():

if(mvKeys.empty())
{
if(mbInitialComputations)
{
ComputeImageBounds(imLeft);
mfGridElementWidthInv=static_cast(FRAME_GRID_COLS)/(mnMaxX-mnMinX);
mfGridElementHeightInv=static_cast(FRAME_GRID_ROWS)/(mnMaxY-mnMinY);
fx = K.at(0,0);
fy = K.at(1,1);
cx = K.at(0,2);
cy = K.at(1,2);
invfx = 1.0f/fx;
invfy = 1.0f/fy;
mbInitialComputations=false;
}
mb = mbf/fx;
mpMutexImu = new std::mutex();
return;
}## Additional Notes

This issue affects robustness when dealing with:

  • Low-light conditions
  • Uniform textures (walls, sky, etc.)
  • Camera initialization frames
  • Temporary image acquisition failures

A similar fix may be needed for RGB-D and Monocular constructors as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions