Calibration Made Easier with HALCON 12

The typical workflow of calibrating an image consists of the following steps:

1) Obtain the camera parameters and pose of the imaging plane with a calibration target
2) Create a rectification map with gen_image_to_world_plane_map
3) Rectify (=calibrate) the image with map_image

There are a few issues you have to deal with every single time:

1) You need to “guess” the conversion from pixels to ‘m’
2) The calibrated image will contain black boundaries
3) Only the image portion with positive world coordinates will be visible

All these can easily be addressed in a generic way. As for determining the conversion to ‘m’, you typically want to preserve the original image resolution. Therefore, you can take the upper left and and upper right corner of the image, map it to world coordinates, and then calculate the pixel size as a ratio of the two distances:

image_points_to_world_plane(CameraParameters, CameraPose, [0,0], [0,CameraParameters[6]-1], ‘m’, X, Y)
distance_pp(X[0], Y[0], X[1], Y[1], Distance)
set_origin_pose(CameraPose, -X[0], -Y[0], 0, CamPoseNew)
PixelSize := Distance/CameraParameters[6]
gen_image_to_world_plane_map(Map, CameraParameters, CameraPose,
    CameraParameters[6], CameraParameters[7], CameraParameters[6], CameraParameters[7],
    PixelSize, ‘bilinear’)

set_origin_pose shifts the origin of the world coordinate system to the upper left corner of the image to maximise the visible area in the calibrated image.

halcon12-calibration

To get rid of the black boundaries (which come from lens and perspective distortion) you can use inner_rectangle1:

map_image(Image, Map, ImageMapped)
inner_rectangle1(ImageMapped, Row1, Column1, Row2, Column2)
crop_rectangle1(ImageMapped, ImagePart, Row1, Column1, Row2, Column2)

Wrap all that code into one or two procedures to simplify calibration.