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
- Run ORB-SLAM3 in stereo mode
- Feed a left image with very few features (e.g., nearly black image, uniform texture, or very dark scene)
- Call
System::TrackStereo() or Tracking::GrabImageStereo()
- 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.
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 insrc/Frame.cc), whenmvKeys.empty()is true, the function returns early without completing necessary initialization. This leaves critical static member variables uninitialized:mfGridElementWidthInvandmfGridElementHeightInvremain uninitializedmbInitialComputationsstaystruefx,fy,cx,cy, etc.) are not setSubsequent code that accesses these uninitialized variables (e.g.,
GetFeaturesInArea(),PosInGrid()) causes undefined behavior and crashes.Steps to Reproduce
System::TrackStereo()orTracking::GrabImageStereo()Expected Behavior
The system should gracefully handle frames with insufficient features:
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:
A similar fix may be needed for RGB-D and Monocular constructors as well.