fig4

Contents

close all
[xg, yg] = meshgrid(linspace(-2,2,5));

pt = [xg(:) yg(:) zeros(25,1)];
cam1.pos = [10 2 5];
cam1.target = [0 0 0];
scl = 0.5;

cam2.pos = [2 10 5];
cam2.target = [0 0 0];

cam3.pos = [8 8 10];
cam3.target = [0 0 0];

% [N M] = size(pt);

figure(1);
daspect([1 1 1]);
view(135,60);
ndx = [1:4 1];
hold on
mesh(xg,yg,zeros(5));

% plot3(pt(ndx,1),pt(ndx,2),pt(ndx,3),'k','LineWidth',1);
cam1 = cam_obj(cam1,scl);
text(cam1.pos(1),cam1.pos(2),cam1.pos(3),'1','FontSize',16);
cam2 = cam_obj(cam2,scl);
text(cam2.pos(1),cam2.pos(2),cam2.pos(3),'2','FontSize',16);
cam3 = cam_obj(cam3,scl);
text(cam3.pos(1),cam3.pos(2),cam3.pos(3),'3','FontSize',16);

hold off
grid;
axis equal
xlabel('x axis');
ylabel('y axis');
zlabel('z axis');
figure(2);
subplot(1,2,1);
[img1, invpt1] = cam_plot(cam1,pt,'g');
mesh(reshape(img1(:,1),[5 5]),reshape(img1(:,2),[5 5]),zeros(5));
axis([-scl scl -scl scl]);
axis square
axis ij
grid
title('camera 1');
subplot(1,2,2);
[img2, invpt2] = cam_plot(cam2,pt,'g');
mesh(reshape(img2(:,1),[5 5]),reshape(img2(:,2),[5 5]),zeros(5));
axis([-scl scl -scl scl]);
axis square
axis ij
grid
title('camera 2');
figure(3);
[img3, invpt3] = cam_plot(cam3,pt,'k');
% plot(img3(:,1),img3(:,2),'ko','LineWidth',1);
mesh(reshape(img3(:,1),[5 5]),reshape(img3(:,2),[5 5]),zeros(5));
axis([-scl scl -scl scl]);
axis square
axis ij
grid on
title('camera 3');
clear imagePoints
imagePoints(:,:,1) = img1;
imagePoints(:,:,2) = img2;
imagePoints(:,:,3) = img3;
worldPoints = pt(:,1:2);

Calibrate the camera

[cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...
    'EstimateSkew', false, 'EstimateTangentialDistortion', false, ...
    'NumRadialDistortionCoefficients', 2, 'WorldUnits', 'in', ...
    'InitialIntrinsicMatrix', eye(3), 'InitialRadialDistortion', []);

cameraParams
save params cameraParams imagePoints worldPoints
Warning: Matrix is singular to working precision. 

cameraParams = 

  cameraParameters with properties:

   Camera Intrinsics
                    IntrinsicMatrix: [3x3 double]
                        FocalLength: [1 1]
                     PrincipalPoint: [0 0]
                               Skew: 0

   Lens Distortion
                   RadialDistortion: [0 0]
               TangentialDistortion: [0 0]

   Camera Extrinsics
                   RotationMatrices: [3x3x3 double]
                 TranslationVectors: [3x3 double]

   Accuracy of Estimation
              MeanReprojectionError: 3.9643e-16
                 ReprojectionErrors: [25x2x3 double]
                  ReprojectedPoints: [25x2x3 double]

   Calibration Settings
                        NumPatterns: 3
                        WorldPoints: [25x2 double]
                         WorldUnits: 'in'
                       EstimateSkew: 0
    NumRadialDistortionCoefficients: 2
       EstimateTangentialDistortion: 0

figure; showReprojectionErrors(cameraParams, 'ScatterPlot');

Visualize pattern locations

figure; showExtrinsics(cameraParams, 'CameraCentric');
R = cameraParams.RotationMatrices(:,:,1)
Tv = cameraParams.TranslationVectors(1,:)
disp('cam1.T''')
disp(cam1.T')
disp('cam1.Tinv');
disp(cam1.Tinv);
R =

   -0.1961    0.4317   -0.8805
    0.9806    0.0863   -0.1761
   -0.0000   -0.8979   -0.4402


Tv =

    0.0000   -0.0000   11.3578

cam1.T'
   -0.1961    0.4317   -0.8805
    0.9806    0.0863   -0.1761
         0   -0.8979   -0.4402
    0.0000         0   11.3578

cam1.Tinv
   -0.1961    0.4317   -0.8805   10.0000
    0.9806    0.0863   -0.1761    2.0000
         0   -0.8979   -0.4402    5.0000

test

Tr = [R [0; 0; 0];Tv 1];
inv(Tr)
ans =

   -0.1961    0.9806   -0.0000         0
    0.4317    0.0863   -0.8979         0
   -0.8805   -0.1761   -0.4402         0
   10.0000    2.0000    5.0000    1.0000