Q:

Wrong rectification in MATLAB

The rectification function in Matlab seems to be responding wrong. Can anyone let  me know if I am getting the right output?
Left Image

Right Image

Anaglyph of unrectified images

Anaglyph of rectified images

Here is my code:
leftImageSnapshot = getsnapshot(handles.vidL);
imshow(leftImageSnapshot);

rightImageSnapshot = getsnapshot(handles.vidR);
imshow(rightImageSnapshot);

[I1Rect,I2Rect]=rectifyStereoImages(I1,I2,stereoParams,'OutputView','valid');
    imshowpair(I1Rect,I2Rect,'falsecolor','ColorChannels','red-cyan');

I was following this link for image rectification. After rectification, the images are supposed to look like the cameras are parallel. But in my case, the vertical disparity still exists in the image.
I am trying to obtain a disparity map for which the vertical disparity should be removed.

A:

My best guess would be that your cameras were moved after you did the calibration. Once you calibrate, the position and orientation of the cameras relative to each other cannot change. If it does, your stereoParams are no longer valid.
To see what went wrong, do the calibration again using the Stereo Camera Calibrator app, and then click "Show Rectified" button at the lower left corner of the main image pane. I will show you a rectified pair of calibration images. If those look ok, then your cameras have moved and you have to take the calibration images again and recalibrate. If the rectified calibration images look bad, then something is wrong with your calibration.
By the way, there is a stereoAnaglyph function, which you can use to create a red-cyan anaglyph.

