필터 지우기
필터 지우기

Correct image distortion based on matlab undistortImage function

조회 수: 2 (최근 30일)
chihyu
chihyu 2022년 6월 10일
답변: Githin George 2023년 10월 27일
hi,
I obtain the camera intrinsic and distortion parameters through the calibration, and I want to correct the image of the test piece of the experiment. The code is presented in below, but error is also emerged. can someone knowledge that what's going on
myFolder = 'C:\Users\yourUserName\Documents\My Pictures';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.bmp'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
IntrinsicMatrix = [5512.29 0 0; 0 5506.17 0; 614.99 255.44 1];
radialDistortion = [-0.09527 4.23896];
cameraParams = cameraParameters('IntrinsicMatrix',IntrinsicMatrix,'RadialDistortion',radialDistortion);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray{k} = imread(fullFileName);
%imshow(imageArray{k}); % Display image.
undistortImage{k} = undistortImage(imageArray{k},cameraParams);
drawnow; % Force display to update immediately.
end
figure; imshowpair(imresize(imageArray{1},0.5),imresize(undistortImage{1},0.5),'montage');
title('Original Image (left) vs. Corrected Image (right)');

답변 (1개)

Githin George
Githin George 2023년 10월 27일
Hello,
I understand you are facing an error when calling the “undistortImage” function.
I tried to reproduce this issue at my end, and I noticed that the problem is caused by the following line.
undistortImage{k} = undistortImage(imageArray{k},cameraParams);
Note that you are shadowing the function “undistortImage” after first function call by declaring a variable with the same name.
Therefore, changing the variable name in the LHS of the assignment statement will fix the issue.
I hope this helps.

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by