Halcon single-camera calibration and distortion correction program
Source:Shenzhen Kai Mo Rui Electronic Technology Co. LTD2026-05-27
Why is single-camera calibration necessary?
General: Distortion correction and one-dimensional and two-dimensional measurement
Distortion Correction:
In geometrical optics and cathode-ray tube (CRT) displays, distortion refers to a deviation from straight-line projection. Simply put, in straight-line projection, a straight line in the scene remains a straight line when projected onto the image. Distortion, on the other hand, means that a straight line, when projected onto the image, no longer retains its straightness. This is an optical aberration. Distortion is a type of phase error that can arise from the camera lens and causes changes in the shape of the objects being photographed, thereby affecting measurements.
My understanding of distortion correction is this: When calibrating a camera, although the calibration target itself also exhibits distortion, we’ve already provided Halcon with accurate data about the calibration target (the circle)—such as the arrangement of the circles, their diameters, and the distances between their centers. By loading multiple images of the calibration target, Halcon can use certain functions to determine the mapping relationship between the distorted calibration target captured by the lens and the undistorted calibration target. In other words, it establishes the mapping between the camera’s intrinsic parameters before distortion correction (capturing distorted images) and its intrinsic parameters after distortion correction (producing undistorted images). By applying this mapping relationship to objects that exhibit distortion during actual imaging, we can complete the distortion correction process.
Steps:
1)Determine the camera intrinsic parameters through calibration.
2)Obtain the undistorted intrinsic parameters from the distorted intrinsic parameters using the chage_radial_distortion_cam_par() function.
3)Determine the mapping relationship between the intrinsic parameters with distortion and the intrinsic parameters without distortion. Use
gen_radial_distortion_map() function
4)Apply the mapping relationship above to the distorted object to complete distortion correction.
One-dimensional and two-dimensional measurements
The dimensions shown in the image are pixel distances. After calibration, we can determine the conversion factor between pixel distances and physical distances, thereby calculating the actual physical dimensions.
Narrow definition: Solve for the camera’s intrinsic parameters, extrinsic parameters, and distortion coefficients to establish the relationship between 2D image pixel coordinates and 3D world coordinates, thereby enabling 3D reconstruction.
Camera intrinsic parameters: These are the camera's inherent properties and are required when performing distortion correction.
Camera extrinsic parameters: After an object is imaged through a lens, it undergoes both rotation and translation. The extrinsic parameters tell us exactly what kind of rotation and translation the object has undergone after imaging. A camera’s extrinsic parameters include a translation vector and a rotation matrix.
Distortion Parameters: The ideal pinhole model is used, but since only a small amount of light passes through the pinhole, the camera exposure would be excessively slow. In practical applications, lenses are therefore employed instead, enabling rapid image formation—but at the cost of introducing distortion. Two types of distortion have a significant impact on projected images: radial distortion and tangential distortion.
Camera distortion and intrinsic parameters are inherent properties of the camera itself and can be calibrated once and used indefinitely. However, since cameras do not perfectly conform to the ideal pinhole imaging model and due to computational errors, results obtained from calibrating with different images will vary. Generally, as long as the reprojection error is very small, the calibration results can be considered reliable.
II. Calibration Procedure
The underlying principle is to identify the landmark points on the displayed calibration board image based on the camera’s pixel size, focal length, and the calibration board’s description file (.descr). By doing so, we can establish the relationship between the actual input parameters of the calibration board (such as Distance and Diameter) and their corresponding pixel sizes in the image, thereby completing the calibration process.

Calibration steps:
1)Use the gen_caltab operator to generate a calibration file.

Before calibration, you need to generate a .descr description file, which defines the relationship between the world coordinate system and the pixel coordinate system. The next time you work on another project, you can simply call up this description file to complete the calibration process.
Operator for generating marker files: gen_caltab (7, number of markers in the x-direction;
7, the number of markers in the y-direction;
0.0075, the distance between the centers of the marked points, in meters;
0.5, the ratio of the diameter of the marking point to the distance between the center of the marking point and the origin;
‘C:/Users/Administrator/Desktop/caltab.descr’, the save path for the calibration board’s description file;
‘caltab.ps’, which contains some information about the calibration board and will be used when printing the calibration board)


2)Open the calibration assistant, load the calibration file, and set the camera parameters (single pixel width and height—check with the camera manufacturer or refer to the manual; camera focal length).

3)Acquire calibration board images from various angles and positions in real time (approximately 9 to 16 images), select one of these images as the reference pose, and then perform calibration.

You can see the camera’s parameters:

4)Save the camera’s intrinsic and extrinsic parameters, and the next time you use the measurement assistant, simply load the intrinsic and extrinsic parameter files directly.

Let me briefly explain how to perform distortion correction: After completing the third step mentioned above—generating calibration data (camera intrinsic and extrinsic parameters)—you can proceed with distortion correction.
*Camera intrinsic parameters
CameraParameters := [0.0375147, -270.806, 8.30152e-006, 8.3e-006, 647.48, 520.914, 1280, 960]
*Camera pose, i.e., extrinsic parameters (rotation matrix + translation vector)
CameraPose := [-0.0091626, -0.00625214, 0.700967, 2.46926, 358.933, 179.443, 0]
*1. Correct radial distortion to obtain the new camera intrinsic parameters.
change_radial_distortion_cam_par ('adaptive', CameraParameters, 0, CamParamOut)
stop ()
Image Acquisition 02: Code generated by Image Acquisition 02
open_framegrabber ('GigEVision', 0, 0, 0, 0, 0, 0, 'default', -1, 'default', -1, 'false', 'default', 'CAMERA_QBY_DM', 0, -1, AcqHandle)
grab_image_start (AcqHandle, -1)
while (true)
grab_image_async (Image, AcqHandle, -1)
*2. Generate a projection map for images affected by radial distortion; the mapping data for the image is stored in the first parameter.
gen_radial_distortion_map (Map, CameraParameters, CamParamOut, ‘bilinear’)
*3. Perform distortion correction on the image
map_image (Image, Map, ImageMapped)
endwhile
close_framegrabber (AcqHandle)
Note: After camera calibration, the camera’s focal length and vertical position must not be adjusted; otherwise, recalibration will be required.
Related News
Introduction to UVC Output for Thermal Imaging Cameras
2026-05-30What Are the Two Spectrums in Dual-Spectrum Fusion?
2026-05-30Want to make images clearer? What are some common image enhancement algorithms?
2026-05-30Dual-Light Fusion: What Does "Dual-Light" Mean?
2026-05-29Basic Optical Concepts - Field of View (FOV)
2026-05-29- 2026-05-29






+8613798538021