Matlab 双目标定 自动化程序

%实现.m文件自动化双目标定

% Auto-generated by stereoCalibrator app on 10-Jul-2019

%-------------------------------------------------------

%function  stereoParams = tereoCameraCalibrator01(file_path01,file_path02)

h=waitbar(0,'计算中,请稍候!');%增加进度条

file_path01 =  'left\';% 图像文件夹路径

file_path02 =  'right\';% 图像文件夹路径

img_path_list01 = dir(strcat(file_path01,'*.png'));%获取该文件夹中所有.PNG格式的图像

img_num01 = length(img_path_list01);%获取图像总数

imageFileNames1 = cell(1,img_num01);

if img_num01 > 0 %有满足条件的图像

for pn = 1:img_num01 %逐一读取图像

            image_name = img_path_list01(pn).name;% 图像名

            %img_origin =  imread(strcat(file_path01,image_name));%读取图像

            imageFileNames1(1,pn) ={ strcat(file_path01,image_name)};

            %fprintf('%d %s\n',pn,strcat(file_path01,image_name));% 显示正在处理的图像名

                        %%此处添加具体的图像处理程序

end

end

img_path_list02 = dir(strcat(file_path02,'*.png'));%获取该文件夹中所有.PNG格式的图像

img_num02 = length(img_path_list02);%获取图像总数

imageFileNames2 = cell(1,img_num02);

if img_num02 > 0 %有满足条件的图像

for pn = 1:img_num02 %逐一读取图像

            image_name = img_path_list02(pn).name;% 图像名

            %img_origin =  imread(strcat(file_path01,image_name));%读取图像

            imageFileNames2(1,pn) ={ strcat(file_path02,image_name)};

            %fprintf('%d %s\n',pn,strcat(file_path01,image_name));% 显示正在处理的图像名

                        %%此处添加具体的图像处理程序

end

end

waitbar(0.1);

% Detect checkerboards in images

[imagePoints, boardSize, imagesUsed] = detectCheckerboardPoints(imageFileNames1, imageFileNames2);

waitbar(0.2);

% Generate world coordinates of the checkerboard keypoints

squareSize = 24;  % in units of 'millimeters'

worldPoints = generateCheckerboardPoints(boardSize, squareSize);

waitbar(0.3);

% Read one of the images from the first stereo pair

I1 = imread(imageFileNames1{1});

[mrows, ncols, ~] = size(I1);

waitbar(0.4);

% Calibrate the camera

[stereoParams, pairsUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...

    'EstimateSkew', false, 'EstimateTangentialDistortion', true, ...

    'NumRadialDistortionCoefficients', 3, 'WorldUnits', 'millimeters', ...

    'InitialIntrinsicMatrix', [], 'InitialRadialDistortion', [], ...

    'ImageSize', [mrows, ncols]);

waitbar(0.8);

% View reprojection errors

h1=figure; showReprojectionErrors(stereoParams);

% Visualize pattern locations

h2=figure; showExtrinsics(stereoParams, 'CameraCentric');

waitbar(0.9);

% Display parameter estimation errors

%displayErrors(estimationErrors, stereoParams);

% You can use the calibration data to rectify stereo images.

%I2 = imread(imageFileNames2{1});

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

% See additional examples of how to use the calibration data.  At the prompt type:

% showdemo('StereoCalibrationAndSceneReconstructionExample')

% showdemo('DepthEstimationFromStereoVideoExample')

fid=fopen('CameraParameter.txt','wt');

fprintf(fid,'stereoParams.RotationOfCamera2:\n');

fprintf(fid,'%f  %f  %f \n',stereoParams.RotationOfCamera2);

fprintf(fid,'stereoParams.TranslationOfCamera2:\n');

fprintf(fid,'%f  %f  %f\n',stereoParams.TranslationOfCamera2);

fprintf(fid,'stereoParams.CameraParameters1.IntrinsicMatrix:\n');

fprintf(fid,'%f  %f  %f\n',stereoParams.CameraParameters1.IntrinsicMatrix);

fprintf(fid,'stereoParams.CameraParameters2.IntrinsicMatrix:\n');

fprintf(fid,'%f  %f  %f\n',stereoParams.CameraParameters2.IntrinsicMatrix);

fclose(fid);

close(h);

%mcc -mv tereoCameraCalibrator01.m

你可能感兴趣的:(Matlab 双目标定 自动化程序)