Halcon calibration

Halcon 2D image sources can be calibrated with a Halcon calibration plate. The calibration is a global calibration and has one of the types:

  • Halcon CalibratedImgSrc: one camera, assigned to a Halcon 2D image source.

  • Halcon MultiCalibratedImgSrc: several cameras in a common coordinate system, assigned to an image source Multi Calibration.

The result is a Halcon camera setup model with the internal camera parameters and the position (pose) of each camera. The image source passes it on with the image data on every acquisition; in the job it is available at the terminal <input>_CalibrationData of the HalconInputImage2DTool or HalconInputData3DTool.

Without a valid Halcon license, a Halcon calibration is not loaded (log: Cannot load Halcon calibration: Invalid license.).

Creating a calibration

A Halcon calibration is usually created in the settings of the image source, in the tab Calibration (2D image sources) or in the group Calibration result (Multi Calibration):

../../../_images/imagesource-calibration-tab.png
  • Calibration: selection of the calibration of the image source. The Halcon calibrations of the matching type are offered; the empty entry means no calibration. The selection takes effect immediately.

  • Recalibrate selected: starts the calibration wizard for the selected calibration.

  • Create a new calibration: creates a new calibration (dialog see below), selects it and starts the calibration wizard.

  • Show results: shows the results of the selected calibration (see Result and export).

For Multi Calibration, the cameras must have been entered under Image Sources beforehand.

Dialog Create a new calibration:

../../../_images/calibration-create.png
  • Name: name of the calibration (suggestion Calib_<date>_<time>). The name must be unique.

  • Location:

    • ‘Calib’ folder (relative to calib.ini) (default): the files are stored in the folder Calib next to the calib.ini.

    • Absolute path with Absolute directory: the files are stored in the given directory. Only full paths with a drive (e.g. C:\Calib) or UNC paths are allowed, also with %ENV% placeholders such as %VIPER_PROJECT_DIR%\Data\Calib. Relative paths and placeholders of a variable that is not set are rejected with an error message. If the directory does not exist, the dialog asks whether it should be created: Yes creates it, No returns to the dialog to correct the path. The path is saved with placeholders; it is resolved on every load and save.

  • Save calibmodel (.ccd): additionally saves the calibration data of Halcon (approx. 6 MB per calibration), e.g. for later analysis.

Alternatively, a Halcon calibration can be created with (+) in the dialog Edit Calibration of the global calibrations (entries Halcon CalibratedImgSrc and Halcon MultiCalibratedImgSrc). There, only the name is asked for; file name and IsSaveCalibModel can be changed in the property list. The calibration is then performed via the image source with Recalibrate selected.

Calibration wizard

The wizard Camera calibration guides you through the calibration in three steps. It is not modal; while it is open, do not edit the calibration elsewhere. Save settings in each step saves the settings of the wizard without calibrating.

Step 1: Calibration plate

../../../_images/calibration-wizard-plate.png
  • Marker Arrangement: Hexagonal (Halcon calibration plates with hexagonally arranged marks, from Halcon 12, default) or Rectangular (older plates with a rectangular arrangement).

  • Description File: description file of the plate, .cpd for Hexagonal, .descr for Rectangular. The default is %HALCONROOT%\calib\calplate_80mm.cpd. The file must match the plate used; Halcon ships the descriptions of the standard plates in the folder calib of the installation.

  • Thickness: thickness of the plate in mm (default: 2). The origin of the world coordinate system is shifted by the thickness, so it lies on the surface the plate rests on.

  • Arrangement settings: parameters of the Halcon operator find_calib_object (e.g. sigma); only parameters with Use are passed.

You can only continue when the description file and the plate type match. The environment variable HALCONROOT must be set.

Step 2: Camera model

../../../_images/calibration-wizard-camera.png
  • Type: AreaScanPoly (area scan camera, polynomial distortion model, default), AreaScanDiv (area scan camera, division model) or LineScan (line scan camera).

  • Telecentric and Tilt (area scan cameras only): telecentric lens or tilt lens.

  • One tab per camera with the start values of the camera parameters: cell size Sx/Sy (µm), focal length (mm), principal point Cx/Cy (pixels, with Auto = image center) and, depending on the model, the distortion parameters; for line scan cameras additionally the motion Vx/Vy/Vz. Cell size and focal length are given in the data sheets of the camera and the lens. Parameters without Use are not optimized during the calibration but kept at their start value.

  • Save/Import per camera, Import all: save or load camera parameters as a Halcon file (.dat, .cal). Clone current to copies the parameters to other cameras, Reset all resets them.

Step 3: Live Calibration

../../../_images/calibration-wizard-live.png

In this step, images of the calibration plate are taken in different positions and the calibration is computed. Three ways of acquisition:

  • Use camera (manually): Start Live/Stop Live; Snap takes one image per camera and searches for the plate, Use accepts the images, Discard discards them.

  • Use camera (automatically): Start Timer opens a countdown window. When the countdown has run out, Viper takes an image per camera, uses it and starts the next countdown. The recording is ended with Stop in the countdown window or a click into the window. The duration of the countdown is set under Settings (Timer, Time to grab in seconds).

  • Use image files: Select takes saved images from directories, one directory with a file filter per camera. The images of the cameras are matched to each other via the image index in the file name. For SimpleFile image sources, the directory and filter of the image source are preset.

For each camera, an image strip shows the accepted images: green contour = plate found, red = error. Single images are removed via the context menu (Remove image). A quality list shows problems of the images (e.g. exposure, contrast, sharpness, size of the marks) whose rating is below the warning threshold.

  • Datas: number of images, Reset discards all images, Calibrate computes the calibration.

  • Results: Show shows the result, Save saves camera parameters, poses and images (see below).

  • Settings: settings of the page, among them the warning threshold of the quality and, under Reference, the image (ImageIndex) and the camera (CamIndex) whose plate position defines the world coordinate system (default: first image of the first camera).

For a good calibration, take images of the plate in many different positions spread over the whole field of view, also tilted. With several cameras, the plate must be visible to at least one camera in each image set; for the common calibration there must be images in which several cameras see the plate at the same time. If the calibration reports No (unique) solution, the images are not sufficient or the start values of the camera parameters do not fit.

Saving: When the wizard is closed after step 3 (with Next or by closing the window), Viper takes over the result into the global calibration and saves the files. If acquired images have not been saved yet, Viper asks first; otherwise the temporary image folder is deleted. During acquisition, Viper stores each accepted image in a temporary folder under the global image path (Calib_<image source>_<date>_<time>).

Result and export

The dialog Calibration results shows the internal camera parameters (tab Internal camera params) and the poses of the cameras (tab External camera params, translation in mm, rotation in degrees). Meanerror is the mean error of the calibration in pixels; the dialog rates values up to 0.10 as a good result.

The dialog Save calibration data exports:

  • External camera parameters (Pose): pose per camera as a Halcon file (write_pose), world coordinate system on the surface the reference plate rests on.

  • Internal camera parameters: camera parameters per camera (write_cam_par).

  • Images: the acquired images, one subfolder per camera; images without a found plate get the prefix Error_.

Poses and camera parameters can only be exported after a successful calibration. %ENV% placeholders in the folders are resolved, missing folders are created.

Files

A Halcon calibration consists of an entry in the calib.ini and up to three files with the same name:

  • .dat: settings of the wizard (plate, camera model, settings).

  • .csm: the camera setup model of Halcon; required at runtime.

  • .ccd: calibration data of Halcon, only with Save calibmodel.

Existing files are overwritten without confirmation when saving. When a calibration is deleted in Edit Calibration, Viper asks whether the files should be deleted as well. For %ENV% placeholders in file names and for files at the old location, see Global calibrations.