⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 caldemo.m

📁 Matlab code of toolbox of camera calibration
💻 M
字号:
clcload cademomore offecho on%% ABOUT CAMERA CALIBRATION%% In geometric camera calibration the intrinsic and extrinsic% camera parameters are computed based on measured image coordinates% of a know calibration target. These parameters may be used to% correct distorted images or image coordinates.%% What we need is the coordinates of the control points and% corresponding image observations. In CACAL routine you must also% specify the configuration of the imaging system. The configuration% data is stored in the file called configc.m and it is acquired% based on the name of the setup like 'pulnix'. The actual calibration% data is stored in data matrices. The first three columns of the data % matrix contain the 3-D coordinates, the next two columns contain % the observations of the control points, and the last three contain% the normal vectors of the calibration object surface around the control% points. CACAL supports up to six data matrices, each containing % information from distict images.%% Press enterpauseclc%% COPLANAR TARGET%% The control points of the calibration target can locate in 3-D% or they can also be coplanar. In case of coplanar target, multiple% images captured from different positions and angles are required.% In the following example three images are used.%% Let us plot the data set. The first data matrix looks like this.%% Press enterpauseclfsubplot(1,2,1)plot3(data1(:,1),data1(:,2),data1(:,3),'x')title('3-D data')axis([-400 500 -400 500 0 500])grid  subplot(1,2,2)plot(data1(:,4),data1(:,5),'r+')axis([0 500 0 500])axis('ij')title('Image data')%% Press enterpauseclc% the second data matrix:clfsubplot(1,2,1)plot3(data2(:,1),data2(:,2),data2(:,3),'x')title('3-D data')axis([-400 500 -400 500 0 500])grid  subplot(1,2,2)plot(data2(:,4),data2(:,5),'r+')axis([0 500 0 500])axis('ij')title('Image data')%% Press enterpauseclc% the third data matrix:clfsubplot(1,2,1)plot3(data3(:,1),data3(:,2),data3(:,3),'x')title('3-D data')axis([-400 500 -400 500 0 500])grid  subplot(1,2,2)plot(data3(:,4),data3(:,5),'r+')axis([0 500 0 500])axis('ij')title('Image data')%% Press enterpauseclc% OK, let's calibrate[par,pos,iter,res,er,C]=cacal('pulnix',data1,data2,data3);% Press enterpauseclc%% 3-D TARGET%% The control point structure can be also three-dimensional. The% advantage which is gained is that only one image is required,% although several images are also supported by CACAL. This demo% uses the following data matrix:%% Press enterpauseclfsubplot(1,2,1)plot3(data3d(:,1),data3d(:,2),data3d(:,3),'x')axis('equal')title('3-D data')  gridsubplot(1,2,2)plot(data3d(:,4),data3d(:,5),'r+')axis([0 700 20 550])axis('ij')title('Image data')%% Press enterpauseclc% OK, let's calibrate again[par,pos,iter,res,er,C]=cacal('sonyz',data3d);% Press enterpauseprevious=std(er);clc%% TREE-STEP PROCEDURE%% The control points are often circular, because they are easy to% make and accurate to measure in subpixel precision from digital% images. However, measuring the centroid of the ellipse (that is% a projection of a circle) introduces a systematic error caused by% perspective projection which is not an affine transformation. % Compensating for this error component requires a three-step calibration% procedure. The Matlab function CACAL performs this procedure. The% additional information is the radius of the points which is embedded% in the configuration file and the normal vector of the surface around% the points. %% Press enterpauseclc% Let's see what happens:[par,pos,iter,res,er,C]=cacal('sony',data3d);% Press enterpause%% If we compare this result with the previous one, we notice that% the standard deviation of the residual is slightly reduced:current=std(er);[previous current]%% Press enterpauseclc%% THE THIRD STEP%% The distorted image coordinates can be corrected by using a simple% inverse model. The parameters of the inverse model are computed% with the routine called INVMODELpar2=invmodel('sony',par);% Press enterpause%% The process of correcting image coordinates is demonstrated by randomly% generating one thousand image coordinate pairs all over the image area.r=[rand(1000,1)*768 rand(1000,1)*576];clfplot(r(:,1),r(:,2),'rx');% Press enterpauseclc% Now, we may corrupt these coordinates with radial and tangential% distortiond=imdist('sony',par,r);holdplot(d(:,1),d(:,2),'go');% Press enterpauseclc% The correction is performed with the Matlab function IMCORRc=imcorr('sony',par2,d);% the difference between the original and the corrected coordinates% may be represented by using histogramsclfsubplot(1,2,1)hist(r(:,1)-c(:,1))title('Error in x direction')xlabel('pixels')subplot(1,2,2)hist(r(:,2)-c(:,2))title('Error in y direction')xlabel('pixels')% As we can see, the error is smaller than 0.01 pixels.echo off

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -