Hello! I'm trying to run an algorithm in Matlab that uses only Matlab's own functions. The program should initially calibrate the cameras, extract their parameters and generate a disparity map through two images rectified with the parameters obtained in the calibration. However when I run the program it generates an error that I do not know how to solve. I use the 2015a version with the toolbox "Computer Vision System" installed and for the calibration I am using a checkered board. 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 the acquisition of images I used a distance of 10 cm between the cameras and I made sure that both were parallel and aligned correctly. All images were taken by a mobile camera (Nokia Lumia 520).
Here is an image of the board I used to calibrate the stereo pair:
If anyone has any idea what might be happening and could help me, it would be of great help!
Thank you.