ClassesClassesClassesClasses | | | | Operators

radial_distortion_self_calibrationT_radial_distortion_self_calibrationRadialDistortionSelfCalibrationradial_distortion_self_calibrationRadialDistortionSelfCalibrationRadialDistortionSelfCalibration (Operator)

Name

radial_distortion_self_calibrationT_radial_distortion_self_calibrationRadialDistortionSelfCalibrationradial_distortion_self_calibrationRadialDistortionSelfCalibrationRadialDistortionSelfCalibration — Calibrate the radial distortion.

Signature

radial_distortion_self_calibration(Contours : SelectedContours : Width, Height, InlierThreshold, RandSeed, DistortionModel, DistortionCenter, PrincipalPointVar : CameraParam)

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)

Herror radial_distortion_self_calibration(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)

HXLDContArray HXLDContArray::RadialDistortionSelfCalibration(const HTuple& Width, const HTuple& Height, const HTuple& InlierThreshold, const HTuple& RandSeed, const HTuple& DistortionModel, const HTuple& DistortionCenter, const HTuple& PrincipalPointVar, HTuple* CameraParam) const

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)

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

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

void HOperatorSetX.RadialDistortionSelfCalibration(
[in] IHUntypedObjectX* Contours, [out] IHUntypedObjectX*SelectedContours, [in] VARIANT Width, [in] VARIANT Height, [in] VARIANT InlierThreshold, [in] VARIANT RandSeed, [in] VARIANT DistortionModel, [in] VARIANT DistortionCenter, [in] VARIANT PrincipalPointVar, [out] VARIANT* CameraParam)

IHXLDContX* HXLDContX.RadialDistortionSelfCalibration(
[in] Hlong Width, [in] Hlong Height, [in] double InlierThreshold, [in] Hlong RandSeed, [in] BSTR DistortionModel, [in] BSTR DistortionCenter, [in] double PrincipalPointVar, [out] VARIANT* 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)

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

Description

radial_distortion_self_calibrationradial_distortion_self_calibrationRadialDistortionSelfCalibrationradial_distortion_self_calibrationRadialDistortionSelfCalibrationRadialDistortionSelfCalibration estimates the distortion parameters and the distortion center of a lens from a set of XLD ContoursContoursContoursContoursContourscontours. Similar to the operator camera_calibrationcamera_calibrationCameraCalibrationcamera_calibrationCameraCalibrationCameraCalibration, the distortion parameters are returned in the parameter CameraParamCameraParamCameraParamCameraParamCameraParamcameraParam. By passing this parameter on to the operators change_radial_distortion_cam_parchange_radial_distortion_cam_parChangeRadialDistortionCamParchange_radial_distortion_cam_parChangeRadialDistortionCamParChangeRadialDistortionCamPar and change_radial_distortion_imagechange_radial_distortion_imageChangeRadialDistortionImagechange_radial_distortion_imageChangeRadialDistortionImageChangeRadialDistortionImage, you can remove radial distortions from images. Additionally, change_radial_distortion_imagechange_radial_distortion_imageChangeRadialDistortionImagechange_radial_distortion_imageChangeRadialDistortionImageChangeRadialDistortionImage returns the contours SelectedContoursSelectedContoursSelectedContoursSelectedContoursSelectedContoursselectedContours that were chosen for the calibration process.

Note, however, that you cannot perform 3D measurements in world coordinates with this operator because it does not calibrate the focal length and the scaling factors.

The distortion model used in the calibration can be selected with the parameter DistortionModelDistortionModelDistortionModelDistortionModelDistortionModeldistortionModel. By choosing the divison model (DistortionModelDistortionModelDistortionModelDistortionModelDistortionModeldistortionModel = 'division'"division""division""division""division""division"), the distortions are modeled by the distortion parameter kappa (see camera_calibrationcamera_calibrationCameraCalibrationcamera_calibrationCameraCalibrationCameraCalibration). By choosing the polynomial model (DistortionModelDistortionModelDistortionModelDistortionModelDistortionModeldistortionModel = 'polynomial'"polynomial""polynomial""polynomial""polynomial""polynomial"), the distortions are modeled by the radial distortion parameters K1, K2, K3 and the decentering distortion parameters P1, P2 (see camera_calibrationcamera_calibrationCameraCalibrationcamera_calibrationCameraCalibrationCameraCalibration). The center of the distortions c = (c_x, c_y) is assumed to be the principal point of the image. Thus, for DistortionModelDistortionModelDistortionModelDistortionModelDistortionModeldistortionModel = 'division'"division""division""division""division""division", CameraParamCameraParamCameraParamCameraParamCameraParamcameraParam contains f, kappa, s_x, s_y, c_x, c_y, WidthWidthWidthWidthWidthwidth, HeightHeightHeightHeightHeightheight. For DistortionModelDistortionModelDistortionModelDistortionModelDistortionModeldistortionModel = 'polynomial'"polynomial""polynomial""polynomial""polynomial""polynomial", CameraParamCameraParamCameraParamCameraParamCameraParamcameraParam contains f, K1, K2, K3, P1, P2, s_x, s_y, c_x, c_y, WidthWidthWidthWidthWidthwidth, HeightHeightHeightHeightHeightheight. Because the calibration is performed without a calibration object, the focal length f and the scaling factors (s_x, s_y) cannot be determined and are therefore set to 0 and 1, respectively.

The estimation of the distortions is based on the assumption that a significant number of straight lines are visible in the imaged scene. 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.

In the application, edge and line extractors (e.g., edges_sub_pixedges_sub_pixEdgesSubPixedges_sub_pixEdgesSubPixEdgesSubPix or lines_gausslines_gaussLinesGausslines_gaussLinesGaussLinesGauss) are used to extract contours in the image. 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, these contours can be preprocessed (e.g., with segment_contours_xldsegment_contours_xldSegmentContoursXldsegment_contours_xldSegmentContoursXldSegmentContoursXld, union_collinear_contours_xldunion_collinear_contours_xldUnionCollinearContoursXldunion_collinear_contours_xldUnionCollinearContoursXldUnionCollinearContoursXld, union_cocircular_contours_xldunion_cocircular_contours_xldUnionCocircularContoursXldunion_cocircular_contours_xldUnionCocircularContoursXldUnionCocircularContoursXld, or select_shape_xldselect_shape_xldSelectShapeXldselect_shape_xldSelectShapeXldSelectShapeXld) to obtain long linear or circular segments. If a single image does not contain a sufficient number of straight contours in the scene, the contours of multiple images can be used (concat_objconcat_objConcatObjconcat_objConcatObjConcatObj).

The operator automatically estimates those contours from ContoursContoursContoursContoursContourscontours that are images of lines of the image 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.

     m
1  -----
-  \      | d  |  >  InlierThresholdInlierThresholdInlierThresholdInlierThresholdInlierThresholdinlierThreshold * m / 100  = T
m  /      |  j |
   -----
    j=1

The value InlierThresholdInlierThresholdInlierThresholdInlierThresholdInlierThresholdinlierThreshold 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 InlierThresholdInlierThresholdInlierThresholdInlierThresholdInlierThresholdinlierThreshold by scaling it with the reference length (100) and the number of contour points m. Therefore, similar contours are classified alike. Typical values of InlierThresholdInlierThresholdInlierThresholdInlierThresholdInlierThresholdinlierThreshold 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 ContoursContoursContoursContoursContourscontours 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 RandSeedRandSeedRandSeedRandSeedRandSeedrandSeed, 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 distortion parameters (kappa, c_x, c_y) or (K1, K2, K3, P1, P2, c_x, c_y), respectively, are estimated via the methods 'variable'"variable""variable""variable""variable""variable", 'adaptive'"adaptive""adaptive""adaptive""adaptive""adaptive", or 'fixed'"fixed""fixed""fixed""fixed""fixed", which are specified via the parameter DistortionCenterDistortionCenterDistortionCenterDistortionCenterDistortionCenterdistortionCenter. In the default mode 'variable'"variable""variable""variable""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. With the method 'adaptive'"adaptive""adaptive""adaptive""adaptive""adaptive", the distortion center c is at first fixed in the image center. Then, the outliers are eliminated by using the InlierThresholdInlierThresholdInlierThresholdInlierThresholdInlierThresholdinlierThreshold. Finally, the calibration process is rerun by estimating (kappa, c_x, c_y) or (K1, K2, K3, P1, P2, 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). By choosing the method 'fixed'"fixed""fixed""fixed""fixed""fixed", the distortion center will be assumed fixed in the image center and only kappa or (K1, K2, K3, P1, P2), 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 PrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarprincipalPointVar can be used in the methods 'adaptive'"adaptive""adaptive""adaptive""adaptive""adaptive" and 'variable'"variable""variable""variable""variable""variable". If the deviation from the image center should be controlled, PrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarprincipalPointVar 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 PrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarprincipalPointVar should be used in cases of weak distortions or similarly oriented contours. Otherwise, a stable solution cannot be guaranteed.

Owing to the internal algorithm of the calibration, the runtime of radial_distortion_self_calibrationradial_distortion_self_calibrationRadialDistortionSelfCalibrationradial_distortion_self_calibrationRadialDistortionSelfCalibrationRadialDistortionSelfCalibration is shortest for DistortionCenterDistortionCenterDistortionCenterDistortionCenterDistortionCenterdistortionCenter = 'variable'"variable""variable""variable""variable""variable" and PrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarprincipalPointVar = 0. The runtime for DistortionCenterDistortionCenterDistortionCenterDistortionCenterDistortionCenterdistortionCenter = 'variable'"variable""variable""variable""variable""variable" and PrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarprincipalPointVar > 0 increases significantly for smaller values of PrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarprincipalPointVar. The runtimes for DistortionCenterDistortionCenterDistortionCenterDistortionCenterDistortionCenterdistortionCenter = 'adaptive'"adaptive""adaptive""adaptive""adaptive""adaptive" and DistortionCenterDistortionCenterDistortionCenterDistortionCenterDistortionCenterdistortionCenter = 'fixed'"fixed""fixed""fixed""fixed""fixed" are also significantly higher than for DistortionCenterDistortionCenterDistortionCenterDistortionCenterDistortionCenterdistortionCenter = 'variable'"variable""variable""variable""variable""variable" and PrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarprincipalPointVar = 0.

Attention

Since the polynomial model (DistortionModelDistortionModelDistortionModelDistortionModelDistortionModeldistortionModel = 'polynomial'"polynomial""polynomial""polynomial""polynomial""polynomial") uses more parameters than the division model (DistortionModelDistortionModelDistortionModelDistortionModelDistortionModeldistortionModel = 'division'"division""division""division""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 P1, P2. To improve the stability, contours of multiple images can be used. Additional stability can be achieved by setting DistortionCenterDistortionCenterDistortionCenterDistortionCenterDistortionCenterdistortionCenter = 'fixed'"fixed""fixed""fixed""fixed""fixed", DistortionCenterDistortionCenterDistortionCenterDistortionCenterDistortionCenterdistortionCenter = 'adaptive'"adaptive""adaptive""adaptive""adaptive""adaptive", or PrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarprincipalPointVar > 0, which was already mentioned above.

Parallelization

Parameters

ContoursContoursContoursContoursContourscontours (input_object)  xld_cont-array objectHXLDContHXLDContHXLDContArrayHXLDContXHobject

Contours that are available for the calibration.

SelectedContoursSelectedContoursSelectedContoursSelectedContoursSelectedContoursselectedContours (output_object)  xld_cont-array objectHXLDContHXLDContHXLDContArrayHXLDContXHobject *

Contours that were used for the calibration

WidthWidthWidthWidthWidthwidth (input_control)  extent.x HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Width of the images from which the contours were extracted.

Default value: 640

Suggested values: 640, 768

Restriction: Width > 0

HeightHeightHeightHeightHeightheight (input_control)  extent.y HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Height of the images from which the contours were extracted.

Default value: 480

Suggested values: 480, 576

Restriction: Height > 0

InlierThresholdInlierThresholdInlierThresholdInlierThresholdInlierThresholdinlierThreshold (input_control)  real HTupleHTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double) (double)

Threshold for the classification of outliers.

Default value: 0.05

Suggested values: 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1

Restriction: InlierThreshold >= 0

RandSeedRandSeedRandSeedRandSeedRandSeedrandSeed (input_control)  integer HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Seed value for the random number generator.

Default value: 42

DistortionModelDistortionModelDistortionModelDistortionModelDistortionModeldistortionModel (input_control)  string HTupleHTupleHTupleVARIANTHtuple (string) (string) (HString) (char*) (BSTR) (char*)

Determines the distortion model.

Default value: 'division' "division" "division" "division" "division" "division"

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

DistortionCenterDistortionCenterDistortionCenterDistortionCenterDistortionCenterdistortionCenter (input_control)  string HTupleHTupleHTupleVARIANTHtuple (string) (string) (HString) (char*) (BSTR) (char*)

Determines how the distortion center will be estimated.

Default value: 'variable' "variable" "variable" "variable" "variable" "variable"

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

PrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarPrincipalPointVarprincipalPointVar (input_control)  real HTupleHTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double) (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 value: 0.0

Suggested values: 0.0, 5.0, 10.0, 20.0, 50.0, 100.0

Restriction: PrincipalPointVar >= 0.0 && PrincipalPointVar <= 100.0

CameraParamCameraParamCameraParamCameraParamCameraParamcameraParam (output_control)  number-array HTupleHTupleHTupleVARIANTHtuple (real / integer) (double / int / long) (double / Hlong) (double / Hlong) (double / Hlong) (double / Hlong)

Internal camera parameters.

Number of elements: CameraParam == 8 || CameraParam == 12

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_calibrationradial_distortion_self_calibrationRadialDistortionSelfCalibrationradial_distortion_self_calibrationRadialDistortionSelfCalibrationRadialDistortionSelfCalibration returns the value 2 (H_MSG_TRUE). If necessary an exception is raised.

Possible Predecessors

edges_sub_pixedges_sub_pixEdgesSubPixedges_sub_pixEdgesSubPixEdgesSubPix, segment_contours_xldsegment_contours_xldSegmentContoursXldsegment_contours_xldSegmentContoursXldSegmentContoursXld

Possible Successors

change_radial_distortion_cam_parchange_radial_distortion_cam_parChangeRadialDistortionCamParchange_radial_distortion_cam_parChangeRadialDistortionCamParChangeRadialDistortionCamPar, change_radial_distortion_imagechange_radial_distortion_imageChangeRadialDistortionImagechange_radial_distortion_imageChangeRadialDistortionImageChangeRadialDistortionImage

See also

camera_calibrationcamera_calibrationCameraCalibrationcamera_calibrationCameraCalibrationCameraCalibration

References

T. Thormälen, H. Broszio: “Automatic line-based estimation of radial lens distortion”; in: Integrated Computer-Aided Engineering; vol. 12; pp. 177-190; 2005.

Module

Calibration


ClassesClassesClassesClasses | | | | Operators