Home > simulink > camcalp_c.m

camcalp_c

PURPOSE ^

CAMCALP_C Camera calibration matrix from parameters (central projection)

SYNOPSIS ^

function C = camcalp(cp, A, B, C)

DESCRIPTION ^

CAMCALP_C    Camera calibration matrix from parameters (central projection)

    C = CAMCALP_C(cp)
    C = CAMCALP_C(cp, Tcam)
    C = CAMCALP_C(cp, pC, x, z)

    Compute a 3x4 camera calibration matrix from given camera intrinsic
    and extrinsic parameters.
       CP is a camera parameter vector comprising:
        cp(1)   f, the focal length of the lens (m)
            cp(2:3) alpha is a 2-element vector of horizontal and 
            vertical pixel pitch of the sensor (pixels/m)
         cp(4:5) p0 is a 2-element vector of principal point (u0, v0)
            in pixels,
            If length(cp) == 3, then p0 defaults to (0,0)

        Tcam is the pose of the camera wrt the world frame, defaults to
        identity matrix if not given (optical axis along Z-axis).

    Alternatively the camera pose can be given by specifying the coordinates
    of the center, pC, and unit vectors for the camera's x-axis and 
    z-axis (optical axis).

    This camera calibration matrix is for the central projection as 
    commonly used in computer vision literature where the focal point
    is at z=0, and rays pass through the image plane at z=f.  This model
    has no image inversion.

      f, alphax and alphay are commonly known as the intrinsic camera 
    parameters.  Tcam is commonly known as the extrinsic camera parameters.

 NOTE:     that this calibration matrix includes the lens image inversion, so
    that the camera coordinate system is:

        0------------------> X
        |
        |
        |    + (principal point)
        |
        |
        v
 
 SEE ALSO:  camcalp, camera, pulnix

    Copyright (c) Peter Corke, 1999  Machine Vision Toolbox for Matlab

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %CAMCALP_C    Camera calibration matrix from parameters (central projection)
0002 %
0003 %    C = CAMCALP_C(cp)
0004 %    C = CAMCALP_C(cp, Tcam)
0005 %    C = CAMCALP_C(cp, pC, x, z)
0006 %
0007 %    Compute a 3x4 camera calibration matrix from given camera intrinsic
0008 %    and extrinsic parameters.
0009 %       CP is a camera parameter vector comprising:
0010 %        cp(1)   f, the focal length of the lens (m)
0011 %            cp(2:3) alpha is a 2-element vector of horizontal and
0012 %            vertical pixel pitch of the sensor (pixels/m)
0013 %         cp(4:5) p0 is a 2-element vector of principal point (u0, v0)
0014 %            in pixels,
0015 %            If length(cp) == 3, then p0 defaults to (0,0)
0016 %
0017 %        Tcam is the pose of the camera wrt the world frame, defaults to
0018 %        identity matrix if not given (optical axis along Z-axis).
0019 %
0020 %    Alternatively the camera pose can be given by specifying the coordinates
0021 %    of the center, pC, and unit vectors for the camera's x-axis and
0022 %    z-axis (optical axis).
0023 %
0024 %    This camera calibration matrix is for the central projection as
0025 %    commonly used in computer vision literature where the focal point
0026 %    is at z=0, and rays pass through the image plane at z=f.  This model
0027 %    has no image inversion.
0028 %
0029 %      f, alphax and alphay are commonly known as the intrinsic camera
0030 %    parameters.  Tcam is commonly known as the extrinsic camera parameters.
0031 %
0032 % NOTE:     that this calibration matrix includes the lens image inversion, so
0033 %    that the camera coordinate system is:
0034 %
0035 %        0------------------> X
0036 %        |
0037 %        |
0038 %        |    + (principal point)
0039 %        |
0040 %        |
0041 %        v
0042 %
0043 % SEE ALSO:  camcalp, camera, pulnix
0044 %
0045 %    Copyright (c) Peter Corke, 1999  Machine Vision Toolbox for Matlab
0046 
0047 function C = camcalp(cp, A, B, C)
0048     f = cp(1);
0049     alpha = cp(2:3);
0050     if length(cp) <=3,
0051         p0 = [ 0 0];
0052     else
0053         p0 = cp(4:5);
0054     end
0055     if nargin == 1,
0056         Tcam = eye(4);
0057     elseif nargin == 2,
0058         Tcam = A;
0059     elseif nargin == 4,
0060         pC = A(:);
0061         x = unit(B(:));
0062         z = unit(C(:));
0063         if abs(dot(x,z)) > 1e-10,
0064             error('x and z vectors should be orthogonal');
0065         end
0066         R=[x unit(cross(z,x)) z];
0067 
0068         Tcam = transl(pC) * [R zeros(3,1); 0 0 0 1];
0069     end
0070 
0071      C = [    alpha(1) 0 p0(1) 0; 
0072         0 alpha(2) p0(2) 0;
0073         0 0 1 0
0074         ] * [ 1 0 0 0;
0075           0 1 0 0;
0076           0 0 1/f 0;
0077           0 0 0 1] * inv(Tcam);

Generated on Sun 15-Feb-2009 18:09:29 by m2html © 2003