Skip to content

radial_distortion_self_calibrationradial_distortion_self_calibrationRadialDistortionSelfCalibrationRadialDistortionSelfCalibrationradial_distortion_self_calibrationT_radial_distortion_self_calibrationπŸ”—

Short descriptionπŸ”—

radial_distortion_self_calibrationradial_distortion_self_calibrationRadialDistortionSelfCalibrationRadialDistortionSelfCalibrationradial_distortion_self_calibrationT_radial_distortion_self_calibration β€” Calibrate the radial distortion.

SignatureπŸ”—

radial_distortion_self_calibration( xld_cont Contours, out xld_cont SelectedContours, extent.x Width, extent.y Height, real InlierThreshold, integer RandSeed, string DistortionModel, string DistortionCenter, real PrincipalPointVar, out campar CameraParam )radial_distortion_self_calibration( Contours : SelectedContours : Width, Height, InlierThreshold, RandSeed, DistortionModel, DistortionCenter, PrincipalPointVar : CameraParam )void RadialDistortionSelfCalibration( const HObject& Contours, HObject* SelectedContours, const HTuple& Width, const HTuple& Height, const HTuple& InlierThreshold, const HTuple& RandSeed, const HTuple& DistortionModel, const HTuple& DistortionCenter, const HTuple& PrincipalPointVar, HTuple* CameraParam )static void HOperatorSet.RadialDistortionSelfCalibration( HObject contours, out HObject selectedContours, HTuple width, HTuple height, HTuple inlierThreshold, HTuple randSeed, HTuple distortionModel, HTuple distortionCenter, HTuple principalPointVar, out HTuple cameraParam )def radial_distortion_self_calibration( contours: HObject, width: int, height: int, inlier_threshold: float, rand_seed: int, distortion_model: str, distortion_center: str, principal_point_var: float ) -> Tuple[HObject, Sequence[Union[int, float, str]]]

Herror T_radial_distortion_self_calibration( const Hobject Contours, Hobject* SelectedContours, const Htuple Width, const Htuple Height, const Htuple InlierThreshold, const Htuple RandSeed, const Htuple DistortionModel, const Htuple DistortionCenter, const Htuple PrincipalPointVar, Htuple* CameraParam )

HXLDCont HXLDCont::RadialDistortionSelfCalibration( Hlong Width, Hlong Height, double InlierThreshold, Hlong RandSeed, const HString& DistortionModel, const HString& DistortionCenter, double PrincipalPointVar, HCamPar* CameraParam ) const

HXLDCont HXLDCont::RadialDistortionSelfCalibration( Hlong Width, Hlong Height, double InlierThreshold, Hlong RandSeed, const char* DistortionModel, const char* DistortionCenter, double PrincipalPointVar, HCamPar* CameraParam ) const

HXLDCont HXLDCont::RadialDistortionSelfCalibration( Hlong Width, Hlong Height, double InlierThreshold, Hlong RandSeed, const wchar_t* DistortionModel, const wchar_t* DistortionCenter, double PrincipalPointVar, HCamPar* CameraParam ) const (Windows only)

HXLDCont HCamPar::RadialDistortionSelfCalibration( const HXLDCont& Contours, Hlong Width, Hlong Height, double InlierThreshold, Hlong RandSeed, const HString& DistortionModel, const HString& DistortionCenter, double PrincipalPointVar )

HXLDCont HCamPar::RadialDistortionSelfCalibration( const HXLDCont& Contours, Hlong Width, Hlong Height, double InlierThreshold, Hlong RandSeed, const char* DistortionModel, const char* DistortionCenter, double PrincipalPointVar )

HXLDCont HCamPar::RadialDistortionSelfCalibration( const HXLDCont& Contours, Hlong Width, Hlong Height, double InlierThreshold, Hlong RandSeed, const wchar_t* DistortionModel, const wchar_t* DistortionCenter, double PrincipalPointVar ) (Windows only)

HXLDCont HXLDCont.RadialDistortionSelfCalibration( int width, int height, double inlierThreshold, int randSeed, string distortionModel, string distortionCenter, double principalPointVar, out HCamPar cameraParam )

HXLDCont HCamPar.RadialDistortionSelfCalibration( HXLDCont contours, int width, int height, double inlierThreshold, int randSeed, string distortionModel, string distortionCenter, double principalPointVar )

DescriptionπŸ”—

radial_distortion_self_calibrationRadialDistortionSelfCalibration estimates the distortion parameters and the distortion center of a lens from a set of XLD Contourscontourscontours.

The distortion parameters are returned in CameraParamcameraParamcamera_param. Because no other parameters are estimated - particularly not the focal length or the magnification - a telecentric camera model is returned with Magnification 1 and scale factor 1 for \(S_{x}\) and \(S_{y}\). See Calibration for more information on the different camera models.

Application

Based on the result of radial_distortion_self_calibrationRadialDistortionSelfCalibration, you can remove lens distortions from images by passing the parameter CameraParamcameraParamcamera_param, which contains the distortion parameters, to the operators change_radial_distortion_cam_parChangeRadialDistortionCamPar and change_radial_distortion_imageChangeRadialDistortionImage.

Basic principle

The estimation of the distortions is based on the assumption that a significant number of straight lines are visible in the image. Because of lens distortions, these lines will be projected to curved contours. The operator now determines suitable parameters by which the curved contours can be straightened again, thus compensating the lens distortions.

Extract input contours

To get suitable input contours Contourscontourscontours, you can, e.g., use edges_sub_pixEdgesSubPix or lines_gaussLinesGauss. The contours should be equally distributed and should lie near the image border because there the degree of distortion is at its maximum and therefore the calibration is most stable. To improve speed and robustness, you can try to to obtain long linear or circular segments, e.g., with segment_contours_xldSegmentContoursXld, union_collinear_contours_xldUnionCollinearContoursXld, union_cocircular_contours_xldUnionCocircularContoursXld, or select_shape_xldSelectShapeXld. If a single image does not contain enough straight contours in the scene, you can use the contours of multiple images (concat_objConcatObj).

Set parameters for contour selection

The operator automatically estimates those contours from Contourscontourscontours that are images of straight lines in the scene using the robust RANSAC method. The contours that do not fulfill this condition and hence are not suited for the calibration process are called outliers. The operator can cope with a maximum outlier percentage of 50 percent. A contour is classified as an outlier if the mean deviation of the contour from its associated straight line is, after the distortion correction, higher than a given threshold \(T\).

\[\begin{eqnarray*} \frac{1}{m} \sum_{j=1}^m \left| d_{j} \right| > \textrm{InlierThreshold} \cdot \frac{m}{100} = T \end{eqnarray*}\]

The value InlierThresholdinlierThresholdinlier_threshold describes the mean deviation of a contour from its associated line in pixels for a contour that contains 100 points. The actual threshold \(T\) is derived from InlierThresholdinlierThresholdinlier_threshold by scaling it with the reference length (100) and the number of contour points \(m\). Therefore, similar contours are classified alike. Typical values of InlierThresholdinlierThresholdinlier_threshold range from 0.05 to 0.5. The higher the value, the more deviation is tolerated. By choosing the value 0, all the contours of Contourscontourscontours are used for the calibration process. The RANSAC contour selection will then be suppressed to enable a manual contour selection. This can be helpful if the outlier percentage is higher than 50 percent.

With the parameter RandSeedrandSeedrand_seed, you can control the randomized behavior of the RANSAC algorithm and force it to return reproducible results. The parameter is passed as initial value to the internally used random number generator. If it is set to a positive value, the operator returns identical results for each call with identical parameter values. The value set for the HALCON system variable 'seed_rand'"seed_rand" (see set_systemSetSystem) does not affect the results of radial_distortion_self_calibrationRadialDistortionSelfCalibration.

radial_distortion_self_calibrationRadialDistortionSelfCalibration returns the contours that were chosen for the calibration process in SelectedContoursselectedContoursselected_contours.

Select distortion model

The distortion model used in the calibration can be selected with the parameter DistortionModeldistortionModeldistortion_model. By choosing the division model (DistortionModeldistortionModeldistortion_model \(=\) 'division'"division"), the distortions are modeled by the distortion parameter \(\kappa\). By choosing the polynomial model (DistortionModeldistortionModeldistortion_model \(=\) 'polynomial'"polynomial"), the distortions are modeled by the radial distortion parameters \(K_{1}, K_{2}, K_{3}\) and the decentering distortion parameters \(P_{1}, P_{2}\). See Calibration for details on the different camera models.

Set parameters for the distortion center estimation

The starting value for the estimation of the distortion center \(c = (c_{x}, c_{y})\) is the center of the image; the image size is defined by Widthwidthwidth and Heightheightheight.

The distortion parameters \((\kappa, c_{x}, c_{y})\) or \((K_{1}, K_{2}, K_{3}, P_{1}, P_{2}, c_{x}, c_{y})\), respectively, are estimated via the methods 'variable'"variable", 'adaptive'"adaptive", or 'fixed'"fixed", which are specified via the parameter DistortionCenterdistortionCenterdistortion_center:

  • β€˜variable’ In the default mode 'variable'"variable", the distortion center \(c\) is estimated with all the other calibration parameters at the same time. Here, many contours should lie equally distributed near the image borders or the distortion should be high. Otherwise, the search for the distortion center could be ill-posed, which results in instability.

  • β€˜adaptive’ With the method 'adaptive'"adaptive", the distortion center \(c\) is at first fixed in the image center. Then, the outliers are eliminated by using the InlierThresholdinlierThresholdinlier_threshold. Finally, the calibration process is rerun by estimating \((\kappa, c_{x}, c_{y})\) or \((K_{1}, K_{2}, K_{3}, P_{1}, P_{2}, c_{x}, c_{y})\), respectively, which will be accepted if \(c = (c_{x},c_{y})\) results from a stable calibration and lies near the image center. Otherwise, \(c\) will be assumed to lie in the image center. This method should be used if the distortion center can be assumed to lie near the image center and if very few contours are available or the position of other contours is bad (e.g., the contours have the same direction or lie in the same image region).

  • β€˜fixed’ By choosing the method 'fixed'"fixed", the distortion center will be assumed fixed in the image center and only \(\kappa\) or \((K_{1}, K_{2}, K_{3}, P_{1}, P_{2})\), respectively, will be estimated. This method should be used in case of very weak distortions or few contours in bad position.

In order to control the deviation of \(c\) from the image center, the parameter PrincipalPointVarprincipalPointVarprincipal_point_var can be used in the methods 'adaptive'"adaptive" and 'variable'"variable". If the deviation from the image center should be controlled, PrincipalPointVarprincipalPointVarprincipal_point_var must lie between 1 and 100. The higher the value, the more the distortion center can deviate from the image center. By choosing the value 0, the principal point is not controlled, i.e., the principal point is determined solely based on the contours. The parameter PrincipalPointVarprincipalPointVarprincipal_point_var should be used in cases of weak distortions or similarly oriented contours. Otherwise, a stable solution cannot be guaranteed.

Runtime

The runtime of radial_distortion_self_calibrationRadialDistortionSelfCalibration is shortest for \(\textrm{DistortionCenter} = '\textit{variable}'\) and \(\textrm{PrincipalPointVar} = \textit{0}\). The runtime for \(\textrm{DistortionCenter} = '\textit{variable}'\) and \(\textrm{PrincipalPointVar} > \textit{0}\) increases significantly for smaller values of PrincipalPointVarprincipalPointVarprincipal_point_var. The runtimes for \(\textrm{DistortionCenter} = '\textit{adaptive}'\) and \(\textrm{DistortionCenter} = '\textit{fixed}'\) are also significantly higher than for \(\textrm{DistortionCenter} = '\textit{variable}'\) and \(\textrm{PrincipalPointVar} = \textit{0}\).

AttentionπŸ”—

Since the polynomial model (DistortionModeldistortionModeldistortion_model \(=\) 'polynomial'"polynomial") uses more parameters than the division model (DistortionModeldistortionModeldistortion_model \(=\) 'division'"division") the calibration using the polynomial model can be slightly less stable than the calibration using the division model, which becomes noticeable in the accuracy of the decentering distortion parameters \(P_{1}, P_{2}\). To improve the stability, contours of multiple images can be used. Additional stability can be achieved by setting \(\textrm{DistortionCenter} = '\textit{fixed}'\), \(\textrm{DistortionCenter} = '\textit{adaptive}'\), or \(\textrm{PrincipalPointVar} > \textit{0}\), which was already mentioned above.

Execution informationπŸ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

ParametersπŸ”—

Contourscontourscontours (input_object) xld_cont-array β†’ objectobjectHObjectHXLDContHObjectHobject

Contours that are available for the calibration.

SelectedContoursselectedContoursselected_contours (output_object) xld_cont-array β†’ objectobjectHObjectHXLDContHObjectHobject *

Contours that were used for the calibration

Widthwidthwidth (input_control) extent.x β†’ (integer)(integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Width of the images from which the contours were extracted.

Default: 640640
Suggested values: 640, 768640, 768
Restriction: Width > 0

Heightheightheight (input_control) extent.y β†’ (integer)(integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Height of the images from which the contours were extracted.

Default: 480480
Suggested values: 480, 576480, 576
Restriction: Height > 0

InlierThresholdinlierThresholdinlier_threshold (input_control) real β†’ (real)(real)HTuple (double)HTuple (double)floatHtuple (double)

Threshold for the classification of outliers.

Default: 0.050.05
Suggested values: 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1
Restriction: InlierThreshold >= 0

RandSeedrandSeedrand_seed (input_control) integer β†’ (integer)(integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Seed value for the random number generator.

Default: 4242

DistortionModeldistortionModeldistortion_model (input_control) string β†’ (string)(string)HTuple (HString)HTuple (string)strHtuple (char*)

Determines the distortion model.

Default: 'division'"division"
List of values: 'division', 'polynomial'"division", "polynomial"

DistortionCenterdistortionCenterdistortion_center (input_control) string β†’ (string)(string)HTuple (HString)HTuple (string)strHtuple (char*)

Determines how the distortion center will be estimated.

Default: 'variable'"variable"
List of values: 'adaptive', 'fixed', 'variable'"adaptive", "fixed", "variable"

PrincipalPointVarprincipalPointVarprincipal_point_var (input_control) real β†’ (real)(real)HTuple (double)HTuple (double)floatHtuple (double)

Controls the deviation of the distortion center from the image center; larger values allow larger deviations from the image center; 0 switches the penalty term off.

Default: 0.00.0
Suggested values: 0.0, 5.0, 10.0, 20.0, 50.0, 100.00.0, 5.0, 10.0, 20.0, 50.0, 100.0
Restriction: PrincipalPointVar >= 0.0 && PrincipalPointVar <= 100.0

CameraParamcameraParamcamera_param (output_control) campar β†’ (real / integer / string)(real / integer / string)HTuple (double / Hlong / HString)HCamPar, HTuple (double / int / long / string)Sequence[Union[int, float, str]]Htuple (double / Hlong / char*)

Internal camera parameters.

ExampleπŸ”—

(HDevelop)


* Assume that GrayImage is one image in gray values with a
* resolution of 640 x 480 and a suitable number of contours.  Then
* the following example performs the calibration using these
* contours and corrects the image with the estimated distortion
* parameters.
edges_sub_pix (GrayImage, Edges, 'canny', 1.0, 20, 40)
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 8, 4)
radial_distortion_self_calibration (ContoursSplit, SelectedContours, \
                                    640, 480, 0.08, 42, 'division', \
                                    'variable', 0, CameraParam)
get_domain (GrayImage, Domain)
change_radial_distortion_cam_par ('fullsize', CameraParam, 0, CamParamOut)
change_radial_distortion_image (GrayImage, Domain, ImageRectified, \
                                CameraParam, CamParamOut)

ResultπŸ”—

If the parameters are valid, the operator radial_distortion_self_calibrationRadialDistortionSelfCalibration returns the value 2 (H_MSG_TRUE). If necessary an exception is raised.

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

edges_sub_pixEdgesSubPix, segment_contours_xldSegmentContoursXld

Possible successors

change_radial_distortion_cam_parChangeRadialDistortionCamPar, change_radial_distortion_imageChangeRadialDistortionImage

See also

camera_calibrationCameraCalibration

ReferencesπŸ”—

T. ThormΓ€hlen, H. Broszio: ``Automatic line-based estimation of radial lens distortionβ€™β€˜; in: Integrated Computer-Aided Engineering; vol. 12; pp. 177-190; 2005.

ModuleπŸ”—

Calibration