Ask Your Question

Is there a 1-1 correspondence between HALCON and OpenCV calibration parameters?

asked 2019-11-14 05:03:48 -0500

Max Herrmann gravatar image

Are the intrinsic parameters that are returned by a HALCON (v13) calibration the same than the ones returned by OpenCV?

Or is there a 1-1 correspondence between the two representations?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-11-22 04:14:29 -0500

Max Herrmann gravatar image

updated 2019-11-22 04:54:01 -0500

We placed a support request to MVTec and received the following answers (received on Thu NOV 21 2019; 09:27):

A conversion between OpenCV and HALCON calibration parameters is not possible.

Reason is that the HALCON polynomial model uses an equation system where the distorted image coordinates are given on the right. Thus the distortion coefficients describe this computation direction. On the contrary, the OpenCV implementation uses an equation system where the undistorted image coordinates are given on the right. Thus the distortion coefficients describe the inverted direction. Because of the high polynomial grade, a conversion is not possible.

To compare the equations, please refer to operator reference of calibrate_cameras and the OpenCV camera calibration tutorial.

The division model that can be inverted analytically does not exist in OpenCV.

We also got an hdev script for an approximated mapping from HALCON to OpenCV parameters (received Thu NOV 21 2019; 16:27):

<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.2" halcon_version="">
<procedure name="main">
<c>* Parameter</c>
<l>PathImg := './'</l>
<l>PathIdRect := '.rect.'</l>
<l>ZoomDisplay := 0.3</l>
<c>* Distortions from OpenCV</c>
<l>Distortions := [-0.161881, 0.092025, 0.000072, -0.000105, 0.000000]</l>
<c>* Camera matrices from OpenCV</c>
<l>* CamMatrixOpenCV := [1402.101918, 0.000000,    967.367190,\
                   0.000000,    1399.751916, 580.546496,\
                   0.000000,    0.000000,    1.000000]</l>
<c>* CamMatrixOpenCV</c>
<l>Cx := 967.3672</l>
<l>Cy := 580.546496</l>
<l>fxPix := 1402.101918</l>
<l>fyPix := 1399.751916</l>
<l>f := 0.00824144</l>
<l>* ProjectionOpenCV := [  fxPix,    0.000000,    Cx,       0.000000,\
                    0.000000,    fyPix,       Cy,       0.000000,\
                    0.000000,    0.000000,    1.000000, 0.000000,\
                    0,           0,           0,        1        ]</l>
<c>* Initialization</c>
<l>dev_update_off ()</l>
<c>* Prepare the image data.</c>
<l>list_image_files (PathImg, 'png', [], ImageFilesAll)</l>
<l>ImageFilesRectified := regexp_select(ImageFilesAll, PathIdRect)</l>
<l>ImageFilesNonRectified := difference(ImageFilesAll, ImageFilesRectified)</l>
<l>if (|ImageFilesNonRectified| != |ImageFilesRectified|)</l>
<l>    throw (['Uneven amounts of images found, please check the image pairs'])</l>
<c>* Prepare the display</c>
<l>read_image (Image, ImageFilesNonRectified[0])</l>
<l>get_image_size (Image, Width, Height)</l>
<l>for I := 0 to 2 by 1</l>
<l>    dev_open_window (0, I*(Width*ZoomDisplay+12), Width*ZoomDisplay, Height*ZoomDisplay, 'black',</l>
<l>    set_display_font (, 16, 'mono', 'true', 'false')</l>
<c>* Perform the calibration using an arbitrary grid (full image also possible but slow)</c>
<l>gen_grid_region (RegionGrid, 5, 5, 'points', Width, Height)</l>
<l>get_region_points (RegionGrid, Row, Col)</l>
<l>campar_opencv2halcon (Distortions, f, Cx, Cy, fxPix, fyPix, Row, Col, Width, Height, Error, CamParamsOpt)</l>
<l>change_radial_distortion_cam_par ('adaptive', CamParamsOpt, [0,0,0,0,0], CamParamOptRect) </l>
<l>dev_set_window (</l>
<l>dev_disp_text ('Error (pxl): ' + Error, 'window', 'top', 'left', 'black ...
edit flag offensive delete link more


sorry for dv, but just posting a link to SO is sooo lame.

what about writing a real answer here instead ?

berak gravatar imageberak ( 2019-11-22 04:47:11 -0500 )edit

No worries. Copy & paste worked perfectly.

Max Herrmann gravatar imageMax Herrmann ( 2019-11-22 04:54:36 -0500 )edit

Question Tools

1 follower


Asked: 2019-11-14 05:03:48 -0500

Seen: 678 times

Last updated: Nov 22 '19