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 two following sequence:

For area scan cameras:
  [Focus, Kappa, Sx, Sy, Cx, Cy, ImageWidth, ImageHeight]

For line scan cameras:
  [Focus, Kappa, Sx, Sy, Cx, Cy, ImageWidth, ImageHeight, Vx, Vy, Vz]

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.

For the modeling of this projection process which is determined by the used combination of camera, lens, and frame grabber, HALCON provides the following three 3D camera models:

Area scan pinhole camera: The combination of an area scan camera with a lens that effects a perspective projection and that may show radial distortions.

Area scan telecentric camera: The combination of an area scan camera with a telecentric lens that effects a parallel projection and that may show radial distortions.

Line scan pinhole camera: The combination of a line scan camera with a lens that effects a perspective projection and that may show radial distortions.

For area scan cameras, the projection of the point p(c) that is given in camera coordinates into a (sub-)pixel [r,c] in the image consists of the following steps: First, the point is projected into the image plane, i.e., onto the sensor chip. If the underlying camera model is an area scan pinhole camera, 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 an area scan telecentric camera 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

For line scan cameras, also the relative motion between the camera and the object must be modeled. In HALCON, the following assumptions for this motion are made:

  1) the camera moves with constant velocity along a straight line
  2) the orientation of the camera is constant
  3) the motion is equal for all images

The motion is described by the motion vector V = (Vx,Vy,Vz)' that must be given in [meter/scanline] in the camera coordinate system. The motion vector describes the motion of the camera, assuming a fixed object. In fact, this is equivalent to the assumption of a fixed camera with the object travelling along -V.

The camera coordinate system of line scan cameras is defined as follows: The origin of the coordinate system is the center of projection. The z-axis is identical to the optical axis and directed so that the visible points have positive z coordinates. The y-axis is perpendicular to the sensor line and to the z-axis. It is directed so that the motion vector has a positive y-component. The x-axis is perpendicular to the y- and z-axis, so that the x-, y-, and z-axis form a right-handed coordinate system.

As the camera moves over the object during the image acquisition, also the camera coordinate system moves relatively to the object, i.e., each image line has been imaged from a different position. This means, there would be an individual pose for each image line. To make things easier, in HALCON, all transformations from world coordinates into camera coordinates and vice versa are based on the pose of the first image line only. The motion V is taken into account during the projection of the point p(c) into the image. Consequently, only the pose of the first image line is returned by the operators find_marks_and_pose and camera_calibration.

For line scan pinhole cameras, the projection of the point p(c) that is given in the camera coordinate system into a (sub-)pixel [r,c] in the image is defined as follows:

Assuming

           / x \
    p(c) = | y |,
           \ z /
the following set of equations must be solved for m, u', and t:
    m * D * u' = x - t * Vx
   -m * D * pv = y - t * Vy
    m * Focus  = z - t * Vz
with
                   1
    D  = -----------------------
         1 + Kappa*(u'*u' + pv*pv)

    pv = Sy*Cy

This already includes the compensation for radial distortions.

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

    c = u' / Sx + Cx
    r = t

The format of the text file CamParFile 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) ;

Depending on the number of elements of CamParam, the parameter groups Camera:Parameter or LinescanCamera:Parameter, respectively, are written into the text file CamParFile (see read_cam_par for an example). The parameter group Camera:Parameter consits of the 8 interior camera parameters of the area scan camera. The parameter group LinescanCamera:Parameter consists of the 11 interior camera parameters of the line scan camera.


Parameters

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

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

Foundation



Copyright © 1996-2008 MVTec Software GmbH