
function lab8()
	im1 = imread('d:\comp vision\images\stereo1.jpg' );
	im2 = imread('d:\comp vision\images\stereo2.jpg' );
       
	C1 = [0.6596   -0.7391   -0.0615  363.4235;
         -0.1851   -0.1387   -0.9437  342.7417;
          0.0005    0.0003   -0.0003    1.0000];     
	C2 = [0.9234   -0.2221   -0.0257  347.7796;
         -0.0741   -0.2278   -0.9168  339.8960;
          0.0002    0.0004   -0.0002    1.0000];
  
	pt3D = stereo(im1, im2, C1, C2)

	figure(3)
	box(pt3D(1:7,:));
	tetrahedron(pt3D(8:11,:));
	cube(pt3D(12:18,:));
	
	axis equal; rotate3D on; 
	% define base plane
	a(1,:) =   [-150  370 0];
	a(2,:) =   [350  -20  0];
	a(3,:) =   [45  -420  0];
	a(4,:) =   [-460 -25  0];
	face1 = [1 2 3 4];
	patch('Faces',face1,'Vertices',a,'FaceColor', [98, 145, 155]/255);
	
	% use 3 extra point to dtermine calibration object
	pt3D(22,:) = pt3D(19,:) - pt3D(20,:);
	pt3D(23,:) = pt3D(21,:) - pt3D(20,:);
	pt3D(24,:) = [5, 5, 0];  
	face2 = [24 20 19 22
              24 20 21 23];      
	patch('Faces',face2,'Vertices',pt3D,'FaceColor', [145, 145, 137]/255);
	
	% calibartion points
	XYZ = [ 49   0  65     % x y z coords of point 1
           129   0  65     % x y z coords of point 2
            49   0 145     % etc
           129   0 145
            49   0 225
           129   0 225
             0 129  65
             0  49  65
             0 129 145
             0  49 145
             0 129 225
             0  49 225]';
	hold;
	plot3(XYZ(1,:), XYZ(2,:), XYZ(3,:),'.k', 'MarkerSize',10);
	hold
  end
  
function box(boxpts3D)
    boxpts3D(8,:) = - boxpts3D(4,:) + boxpts3D(6,:) + boxpts3D(2,:);
    % define faces from standard numbering
    boxfaces = [4 1 2 3
                 4 3 7 6
                 4 6 5 1
                 8 5 1 2
                 8 2 3 7
                 8 7 6 5];
    patch('Faces',boxfaces,'Vertices',boxpts3D,'FaceColor', [211, 204, 196]/255)
end

function cube(cubepts3D)
    cubepts3D(8,:) = - cubepts3D(4,:) + cubepts3D(6,:) + cubepts3D(2,:);
    % define faces from standard numbering
    cubefaces = [4 1 2 3
                 4 3 7 6
                 4 6 5 1
                 8 5 1 2
                 8 2 3 7
                 8 7 6 5];
    patch('Faces',cubefaces,'Vertices',cubepts3D,'FaceColor', [145, 98, 52]/255)
end

function tetrahedron(tetrahedronpts3D)
    % define faces from standard numbering
    tetrahedronfaces = [1 2 3
                        1 2 4
                        1 3 4
                        2 3 4];     
    patch('Faces',tetrahedronfaces,'Vertices',tetrahedronpts3D,'FaceColor', [211, 65, 66]/255)
end