Stereo Vision in Matlab

Asked

Viewed 189 times

1

Hello! I’m trying to run a matlab algorithm that uses only matlab functions. The program should initially calibrate the cameras, extract their parameters and generate a disparity map through two rectified images with the parameters obtained in the calibration. However when I run the program it generates an error that I don’t know how to fix. I use the 2015a version with the Toolbox "Computer Vision System" installed and for calibration I am using a checkerboard. Below is the algorithm I’m using:

%Carrega os pares de imagens para calibração
ParesdeImagens = 11;
arquivoImagens1 = cell(1,ParesdeImagens);
arquivoImagens2 = cell(1,ParesdeImagens);
imagemDir = fullfile('C:','Users','carlo','Documents','Iniciacao','Matlab','Principal');
for i = 1:ParesdeImagens
   arquivoImagens1{i} = fullfile(imagemDir,  sprintf('left%02d.jpg', i));
   arquivoImagens2{i} = fullfile(imagemDir,  sprintf('right%02d.jpg', i));
end

%Realiza a detecção dos cantos no tabuleiro
[imagePoints, boardSize, pairsUsed] = detectCheckerboardPoints(arquivoImagens1, arquivoImagens2);

%Exibe os pontos identificados da camera esquerda
arquivoImagens1=arquivoImagens1(pairsUsed);
figure;
for i= 1:numel(arquivoImagens1)
   I= imread(arquivoImagens1{i});
   subplot(3,4,i);
   imshow(I);
   hold on;
   plot(imagePoints(:,1,i,1),imagePoints(:,2,i,1),'*-g');
end

%Exibe os pontos identificados da camera direita
arquivoImagens2=arquivoImagens2(pairsUsed);
figure;
for i= 1:numel(arquivoImagens2)
   I= imread(arquivoImagens2{i});
   subplot(3,4,i);
   imshow(I);
   hold on;
   plot(imagePoints(:,1,i,2),imagePoints(:,2,i,2),'*-g');
end

%Computa as coordenadas reais do tabuleiro  
squareSize = 29; % milimetros
worldPoints = generateCheckerboardPoints(boardSize, squareSize);

%Computa os parâmetros estéreos  
stereoParams = estimateCameraParameters(imagePoints, worldPoints);

%Avalia a precisão da calibração
figure;
showReprojectionErrors(stereoParams);

% Lê um par de imagens
I1 = imread('esquerda.jpg');
I2 = imread('direita.jpg');

%Retifica as imagens
[J1, J2] = rectifyStereoImages(I1, I2, stereoParams);

%Exibe as imagens antes da retificação
figure;
imshow(stereoAnaglyph(I1, I2));
title('Antes da Retificacao');

%Exibe as imagens depois da retificação
figure;
imshow(stereoAnaglyph(J1, J2));
title('Depois da Retificacao');

%Gera o mapa de disparidade
disparityMap = disparity(rgb2gray(J1), rgb2gray(J2));
figure;
imshow(disparityMap, [0, 64]);
colormap('jet');
colorbar;
title('Mapa de Disparidade');

When I run the program I get the following error message:

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, the corners of all images of both pairs were correctly recognized, and an error of 4 pixels was estimated. For imaging I used a 10 cm distance between the cameras and made sure they were both parallel and aligned correctly. All images were taken by a mobile camera ( Nokia Lumia 520 ).

Here’s a screenshot of the board I used to calibrate the stereo pair: inserir a descrição da imagem aqui

If anyone has any idea what might be going on and can assist me would be of great help!

Thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.