www.gusucode.com > vision 源码程序 matlab案例代码 > vision/UndistortCheckerboardPointsExample.m

    %% Undistort Checkerboard Points
%
%% 
% Create an imageSet object containing calibration images.
images = imageSet(fullfile(toolboxdir('vision'),'visiondata',...
    'calibration','fishEye'));
imageFileNames = images.ImageLocation;
%% 
% Detect the calibration pattern.
[imagePoints,boardSize] = detectCheckerboardPoints(imageFileNames);
%% 
% Generate the world coordinates related to the corners of the squares. 
% Square size is in millimeters.
squareSize = 29; 
worldPoints = generateCheckerboardPoints(boardSize,squareSize); 
%% 
% Calibrate the camera.
params = estimateCameraParameters(imagePoints,worldPoints);
%% 
% Load an image and detect the checkerboard points.
I = images.read(10);
points = detectCheckerboardPoints(I);
%% 
% Undistort the points.
undistortedPoints = undistortPoints(points,params);
%% 
% Undistort the image.
[J, newOrigin] = undistortImage(I,params,'OutputView','full');
%% 
% Translate the undistorted points.
undistortedPoints = [undistortedPoints(:,1) - newOrigin(1),...
    undistortedPoints(:,2) - newOrigin(2)];
%% 
% Display the results.
   figure; 
   imshow(I); 
   hold on;
   plot(points(:, 1),points(:,2),'r*-');
   title('Detected Points'); 
   hold off;

   figure; 
   imshow(J); 
   hold on;
   plot(undistortedPoints(:,1),undistortedPoints(:,2),'g*-');
   title('Undistorted Points'); 
   hold off;