Skip to content

Bug in stereo_match.cpp #15779

@oleg-alexandrov

Description

@oleg-alexandrov
System information (version)
  • OpenCV => ❔
  • Operating System / Platform => ❔
  • Compiler => ❔
Detailed description

The stereo_match.cpp code (https://github.com/opencv/opencv/blob/master/samples/cpp/stereo_match.cpp) has a scaling issue that took me 2 days to track down. The computed disparity is a signed int16, and is scaled by a factor of 16 compared to the true disparity, as per the documentation. The disparity thus must be converted to float and divided by 16.0 before invoking reprojectImageTo3D(). As it is now, since this division is not done, the result of reprojectImageTo3D() is wrong, as is at 1/16-the the scale.

Suggested fix:

Mat float_disp;
disp.convertTo(float_disp, CV_32F, 1.0f/16.0f);
reprojectImageTo3D(float_disp, xyz, Q, true);
Steps to reproduce

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions