Comprehensive Guide to Halcon Camera Calibration and Precision Measurement Techniques

Camera calibration primarily addresses geometric distortion correction and coordinate system transformations between image space and the real world. Key objectives include compensating for radial and perspective distortions, determining camera intrinsics and extrinsics, and converting pixel coordinates to physical measurements.

Distortion Models

Halcon employs specific mathematical models to describe lens imperfections.

Division Model

This model utilizes a single parameter k to approximate radial deformation, assuming the optical center aligns with the image center.

  • Positive k (> 0): Pincushion distortion
  • Zero k (= 0): No distortion
  • Negative k (< 0): Barrel distortion

Operator: area_scan_division

Polynomial Model

Designed for scenarios where the optical center deviates from the image center, this approach uses three parameters (K1, K2, K3) for radial deformation and two parameters (P1, P2) for decentering distortion.

Operator: area_scan_polynomial

Optical Considerations

Perspective and Tilt

Perspective distortion involves depth-related size changes where objects appear smaller when further away. While a standard single-camera setup cannot fully correct perspective effects without hardware intervention, lens tilt can be modeled. Different lens types offer varying capabilities:

  • Standard FA Lenses: Require tilt modeling.
  • Telecentric Lenses: Available in object-side, image-side, and bilateral variants to eliminate perspective error.

Intrinsic Parameters

Understanding camera specifications is essential for initialization:

  • Focus: Focal length (set to 0 for telecentric lenses).
  • Magnification: Relevant primari for object-side telecentric systems.
  • ImagePlaneDist: Distance from aperture stop to sensor.
  • Tilt/Rot: Describes angular deviations relative to the sensor plane.
  • Sx/Sy: Scaling factors for pixel density.
  • Cx/Cy: Principal point coordinates (image center).

Calibration Targets

Selecting the appropriate target affects robustness.

Hexagonal Grid

  • Requires visibility of at least two markers to orient correctly.
  • Origin defined at the first marker's center.
  • Advantage: Does not need full board visibility within the frame.
  • Operator: create_caltab

Triangular Grid

  • All target features must be fully visible.
  • Origin located at the geometric center of the surface.
  • Operator: gen_caltab

Implementation Workflow

The following procedure demonstrates initializing a division model, capturing images, performing calibration, and transforming coordinates.

*--- Initialization ---*
* Define paths
Path := 'data/images/'
PlateDesc := 'calib_board.descr'

* Initialize parameters (Division Model: Telecentric)
* Syntax: [ModelName, Magnification, Kappa, XPixelEq, YPixelEq, Cx, Cy, Width, Height]
ModelSpecs := ['division', 0.5, 0.0, 0.0000045, 0.0000045, 1920, 1080, 3840, 2160]

* Create calibration data handle
create_calib_data ('calibration_object', 1, 1, hCalibData)

* Set camera intrinsic parameters
set_calib_data_cam_param (hCalibData, 0, [], ModelSpecs)
set_calib_data_calib_object (hCalibData, 0, PlateDesc)

*--- Data Acquisition ---*
* List of images captured from different angles
ImgList := ['/path/to/image_01.png', '/path/to/image_02.png', '/path/to/image_03.png']

For Index := 0 To |ImgList|-1
    read_image (ImageRaw, ImgList[Index])
    
    * Detect calibration pattern
    * sigma determines detection sensitivity
    find_calib_object (ImageRaw, hCalibData, 0, 0, Index, 'sigma', 1)
Endfor

*--- Calibration Execution ---*
* Execute optimization
ErrorMetric := calibrate_cameras (hCalibData)

* Retrieve results
get_calib_data (hCalibData, 'camera', 0, 'params', lIntrinsics)
get_calib_data (hCalibData, 'calib_obj_pose', [0, 0], 'pose', lExtrinsics)

* Adjust for plate thickness if measuring object height rather than surface
SetZOffset := 0.003  * e.g., 3mm thickness
set_origin_pose (lExtrinsics, 0.0, 0.0, SetZOffset, lAdjustedPose)

*--- Coordinate Transformation ---*
* Convert 2D image points to 3D world coordinates
ImageRows := [150.5, 300.2]
ImageCols := [120.5, 450.8]

* Transform pixels to world units (mm)
image_points_to_world_plane (lIntrinsics, lAdjustedPose, ImageRows, ImageCols, 'mm', WorldX, WorldY)

* Measure distance between two points in world space
DistanceMM := distance_pp (WorldX[0], WorldY[0], WorldX[1], WorldY[1])

* Compare against pixel distance for pixel-to-mm ratio validation
PixelDist := distance_pp (ImageRows[0], ImageCols[0], ImageRows[1], ImageCols[1])
PixelScale := DistanceMM / PixelDist

Best Practices for Accuracy

  1. System Stability: Do not alter focus, aperture, or mechanical position after calibration.
  2. Board Coverage: Ensure the calibration target occupies a significant portion of the field of view across multiple poses.
  3. Angles: Capture images with slight tilts (approx. 30°) around all axes to constrain the optimization variables better.
  4. Marker Quality: Marker diameters should ideal exceed 40 pixels. High contrast is required (gray value difference > 100), avoiding saturation (max < 240).
  5. Lighting: Uniform illumination without specular reflections is critical.

Advanced Rectification Methods

Standard Model Limitations

Traditional multi-image calibration requires full board visibility, which may be obstructed by fixtures in industrial environments. Additionally, heavy reliance on fitting across many images increases computational cost and susceptibility to lighting variations.

Arbitrary Distortion Maps

For high-precision tasks involving occlusions or non-standard setups, constructing a custom grid map offers flexibility.

Workflow:

  1. Calculate initial pixel-to-world scale using known marker spacing.
  2. Generate a virtual grid covering the region of interest.
  3. Align extracted corners with the theoretical grid points.
  4. Populate missing areas via interpolation if necessary.
  5. Generate a rectification map using gen_arbitrary_distortion_map.

Mesh Rectification

When dealing with complex deformations beyond simple lens models, mesh-based approaches can be employed.

  • Operator: gen_grid_rectification_map
  • Concept: Creates a mapping from a distorted source image to an aligned destination based on user-defined control points.

Handling Occlusions: If parts of the target are blocked, virtual filling techniques combined with arbitrary maps prevent "holes" in the resulting transformation.

Conclusion on Distortion Types

While radial distortion is effectively corrected via software calibration (Division or Polynomial models), perspective distortion remains largely a hardware constraint. Telecentric optics provide the optimal solution for eliminating perspective error in metrology applications, ensuring measurement accuracy regardless of object distance variations.

Tags: Halcon Computer Vision Camera Calibration Precision Measurement Lens Distortion

Posted on Thu, 07 May 2026 18:33:51 +0000 by possiblyB9