Search code examples
matlabimage-processing3dmatlab-cvststereo-3d

"rectifyStereoImages" in MATLAB not working


I am working in the Stereo Vision for the first time. I am trying to rectify the stereoImages. The following is the result enter image description here

I can't understand why the image is getting cropped

The following is my code

% Read in the stereo pair of images.
I1 = imread('sceneReconstructionLeft.jpg');
I2 = imread('sceneReconstructionRight.jpg');

% Rectify the images.
[J1, J2] = rectifyStereoImages(I1, I2, stereoParams);

% Display the images before rectification.
figure;
imshow(stereoAnaglyph(I1, I2), 'InitialMagnification', 50);
title('Before Rectification');

% Display the images after rectification.
figure;
imshow(stereoAnaglyph(J1, J2), 'InitialMagnification', 50);
title('After Rectification');

I am trying to follow this guide

http://www.mathworks.com/help/vision/examples/stereo-calibration-and-scene-reconstruction.html

The images I used

enter image description here

enter image description here


Solution

  • Try doing the following:

    [J1, J2] = rectifyStereoImages(I1, I2, stereoParams, 'OutputView', 'Full');
    

    This way you will see the entire images. enter image description here

    By default, rectifyStereoImages crops the output images to only contain the overlap between the two frames. In this case the overlap is very small compared to the disparity.

    What is happening here is that the baseline (distance between the cameras) is too wide, and the distance to the objects is too short. This results in a very large disparity, which will be hard to compute reliably. I suggest that you either move the cameras closer together, or move the cameras further away from the objects of interest, or both.