write_cam_par ( : : CamParam, CamParFile : )

Write the interior camera parameters to text file.

write_cam_par is used to write the interior camera parameters CamParam to a text file with name CamParFile. CamParam is a tuple that contains the interior camera parameters in the following sequence:

  [Focus, Kappa, Sx, Sy, Cx, Cy, ImageWidth, ImageHeight]

The interior camera parameters describe the projection process of the used combination of camera, lens, and frame grabber; they can be determined calibrating the camera, see camera_calibration.

The projection of a point p(c) given in camera cordinates into a (sub-)pixel [r,c] in the image consists of multiple steps: First, the point is projected into the image plane, i.e., onto the sensor chip. If the underlying camera model is a pinhole camera with radial distortions, i.e., if the focal length passed in CamParam is greater than 0, the projection is described by the following equations:

           / x \
    p(c) = | y |
           \ z /

    u = Focus * x / z
    v = Focus * y / z

In contrast, if the focal length is passed as 0 in CamParam, the camera model of a telecentric camera with radial distortions is used, i.e., it is assumed that the optics of the lens of the camera performs a parallel projection. In this case, the corresponding equations are:

           / x \
    p(c) = | y |
           \ z /

    u = x 
    v = y

The following equations compensate for radial distortion:

   u' = (2*u) / (1+sqrt(1-4*Kappa*(u^2+v^2)))
   v' = (2*v) / (1+sqrt(1-4*Kappa*(u^2+v^2)))

Finally, the point is transformed from the image plane coordinate system into the image coordinate system, i.e., the pixel coordinate system:

    c = u' / Sx + Cx
    r = v' / Sy + Cy

The format of the text file is a (HALCON-independent) generic parameter description. It allows to group arbitrary sets of parameters hierarchically. The description of a single parameter within a parameter group consists of the following 3 lines:

   Name : Shortname : Actual value ; 
    Type : Lower bound (optional) : Upper bound (optional) ;
    Description (optional) ;

The operator write_cam_par writes the parameter group Camera:Parameter into the text file CamParFile. This parameter group consists of the 8 interior camera parameters, but in a different sequence than in CamParam (see read_cam_par for an example).


Parameters

CamParam (input_control)
number-array -> real / integer
Interior camera parameters.
Number of elements: 8

CamParFile (input_control)
string -> string
File name of interior camera parameters.
Default value: 'campar.dat'
List of values: 'campar.dat', 'campar.initial', 'campar.final'


Example
*  read calibration images 
read_image(Image1, 'calib-01') 
read_image(Image2, 'calib-02') 
read_image(Image3, 'calib-03') 
*  find calibration pattern
find_caltab(Image1, Caltab1, 'caltab.descr', 3, 112, 5) 
find_caltab(Image2, Caltab2, 'caltab.descr', 3, 112, 5) 
find_caltab(Image3, Caltab3, 'caltab.descr', 3, 112, 5) 
*  find calibration marks and start poses
StartCamPar := [Focus, Kappa, Sx, Sy, Cx, Cy, ImageWidth, ImageHeight]
find_marks_and_pose(Image1, Caltab1, 'caltab.descr', StartCamPar,
                    128, 10, 18, 0.9, 15.0, 100.0, RCoord1, CCoord1,
                    StartPose1) 
find_marks_and_pose(Image2, Caltab2, 'caltab.descr', StartCamPar,
                    128, 10, 18, 0.9, 15.0, 100.0, RCoord2, CCoord2,
                    StartPose2) 
find_marks_and_pose(Image3, Caltab3, 'caltab.descr', StartCamPar,
                    128, 10, 18, 0.9, 15.0, 100.0, RCoord3, CCoord3,
                    StartPose3) 
*  read 3D positions of calibration marks 
caltab_points('caltab.descr', NX, NY, NZ) 
*  camera calibration 
camera_calibration(NX, NY, NZ, [RCoord1, RCoord2, RCoord3],
                   [CCoord1, CCoord2, CCoord3], StartCamPar,
                   [StartPose1, StartPose2, StartPose3], 'all',
                   CamParam, NFinalPose, Errors) 
*  write interior camera parameters to file
write_cam_par(CamParam, 'campar.dat')

Result

write_cam_par returns 2 (H_MSG_TRUE) if all parameter values are correct and the file has been written successfully. If necessary an exception handling is raised.


Parallelization Information

write_cam_par is local and processed completely exclusively without parallelization.


Possible Predecessors

camera_calibration


See also

find_caltab, find_marks_and_pose, camera_calibration, disp_caltab, sim_caltab, read_cam_par, write_pose, read_pose, project_3d_point, get_line_of_sight


Module

Camera calibration



Copyright © 1996-2005 MVTec Software GmbH