1
votes

I am working on Stereo vision task and trying to run this algorithm:

numImagePairs = 11;
imageFiles1 = cell(1,numImagePairs);
imageFiles2 = cell(1,numImagePairs);
imagemDir = fullfile('C:','Users','carlo','Documents','Iniciacao','Matlab','Principal');

for i = 1:numImagePairs
imageFiles1{i} = fullfile(imagemDir, sprintf('left%02d.jpg',i));
imageFiles2{i} = fullfile(imagemDir, sprintf('right%02d.jpg',i));
end

%Detect the checkerboard
[imagePoints,boardSize,pairsUsed] = detectCheckerboardPoints(imageFiles1,imageFiles2);

%Generate world coordinates of the checkerboard points
squareSize=29; %millimeters
worldPoints= generateCheckerboardPoints(boardSize, squareSize);

%Compute the stereo camera parameters
stereoParams= estimateCameraParameters(imagePoints,worldPoints);


%Evaluate calibration accuracy
figure;
showReprojectionErrors(stereoParams);

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

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

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

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


%Generate the disparity map
disparityMap = disparity(J1,J2);
figure;
imshow(disparityMap, [0,64]);
colormap('jet');
colorbar;
title('Disparity Map');

EDIT

Running this leads to the output:

Operands to the || and && operators must be convertible to logical scalar values.

Error in vision.internal.calibration.CameraParametersImpl/getValidBounds (line 883)
        if isempty(coder.target) && (left > right || top > bot)

Error in vision.internal.calibration.CameraParametersImpl/computeUndistortBounds (line 785)
                [xBounds, yBounds] = getValidBounds(this, undistortedMask, ...

Error in vision.internal.calibration.StereoParametersImpl/computeOutputBounds (line 371)
        [xBoundsUndistort1, yBoundsUndistort1] = ...

Error in vision.internal.calibration.StereoParametersImpl/computeRectificationParameters (line 271)
        [xBounds, yBounds] = computeOutputBounds(this, imageSize, ...

Error in vision.internal.calibration.StereoParametersImpl/rectifyStereoImagesImpl (line 190)
            [H1, H2, Q, xBounds, yBounds] = ...

Error in rectifyStereoImages (line 99)
[rectifiedImage1, rectifiedImage2] = rectifyStereoImagesImpl(stereoParams, ...

Error in new_project (line 55)
[J1, J2] = rectifyStereoImages(I1, I2, stereoParams);

In this case all the corners of all images were detected, which means that the calibration apparently is running ok and are 11 centimeters of distance between the two cameras.

1

1 Answers

0
votes

This error indicates that rectifyStereoImages cannot compute the bounds of the output image. This usually means that you need more calibration images to get a better estimate of the distortion coefficients. You want to make sure that you get points close to edges and corners of your field of view.

First, try the following:

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

Also, it would be very helpful if you could post a few of your calibration images.