Camera Calibration Program: NOTE: e:/calibration_image: For calibration image file path ' E:/CALIBRATION_DESCRIPTION/CALTAB_123MM.DESCR: For calibration description file path * Ride ant on high speed * Program starts List_files (' e:/calibration_image ', ' files ', imagefiles)tmpctrl_allmarkrows: = []tmpctrl_allmarkcolumns: = []tmpctrl_startposes: = []Tmpctrl_referenceindex: = 0startparameters: = [0.008,0,5.2e-006,5.2e-006,640,512,1280,1024]For Index: = 0 to | Imagefiles|-1 by 1read_image (image, Imagefiles[index])Find_caltab (Image, tmpobj_plateregion, ' E:/calibration_description/caltab_123mm.descr ', 3, 5)find_marks_and_pose (Image, tmpobj_plateregion, ' E:/CALIBRATION_DESCRIPTION/CALTAB_123MM.DESCR ', Startparameters, Max, ten, 0.9, Tmpctrl_markrows, Tmpctrl_markcolumns, Tmpctrl_estimatedpose)tmpctrl_allmarkrows: = [Tmpctrl_allmarkrows, tmpctrl_markrows]tmpctrl_allmarkcolumns: = [Tmpctrl_allmarkcolumns, Tmpctrl_markcolumns]tmpctrl_startposes: = [tmpctrl_startposes, Tmpctrl_estimatedpose]endforcaltab_points (' E:/calibration_description/caltab_123mm.descr ', tmpctrl_x, tmpctrl_y, TmpCtrl_Z)camera_calibration (tmpctrl_x, tmpctrl_y, Tmpctrl_z, Tmpctrl_allmarkrows, Tmpctrl_allmarkcolumns, Startparameters, tmpctrl_startposes, ' All ', Cameraparameters, tmpctrl_finalposes, tmpctrl_errors)Tuple_select_range (tmpctrl_finalposes, 7*tmpctrl_referenceindex, 7*tmpctrl_referenceindex + 6, CameraPose)set_origin_pose (camerapose, 0.0, 0.0, 0.001, camerapose)Stop ()
first, read into the image, the function is as followslist_files (' e:/calibration_image ', ' files ', imagefiles)For Index: = 0 to | Imagefiles|-1 by 1read_image (image, Imagefiles[index])endfornotes:' E:/calibration_image ': For image path, the image file index is starting from 0, so| imagefiles|(number of files) minus 1. Operator: Read_image (: image:filename): Reads an image named FileName.
Second, extract the image images on the plate to determine the circular mark on the calibration plate effective area, operator is as follows:Find_caltab (image:caltab:caltabdescrfile,sizegauss,markthresh,mindiammarks:)
The two-dimensional coordinates of the circular markers on the calibration plate are determined and the initial values of the external parameters of the camera are obtained, and the operators are as follows:Find_marks_and_pose (image,caltabregion:: Caltabdescrfile, Startcamparam, Startthresh, DeltaThre Sh,minthresh,alpha,mincontlength,maxdiammarks:rcoord,ccoord, Startpose)
notes
: function Find_caltab the search for the calibration plate in the image is based on the characteristic of the calibration plate-there is a black standard point in a bright area. First, the Gaussian filter is used to smooth the image. The parameter Sizegauss determines the size of the Gaussian filter. The larger the Sizegauss value, the greater the amplitude of the image smoothing, which is necessary when the image noise is relatively large. After the image smoothing operation, in order to find the location of the calibration plate, we do a threshold segmentation, you can refer to the grayscale histogram, the gray value range from the minimum value of Markthresh to the maximum value of 255, therefore, the Markthresh must be less than the white area of the calibration plate gray value, and preferably greater than the gray values of other large areas of the image in the lighter area. In a plurality of regions where the threshold is split, the convex region that contains the number of holes that best matches the number of fixed points on the calibration plate is selected. To reduce the noise impact, holes with a diameter of less than Mindiammarks will be removed. The number of marker points can be read from the Calibration board description file (caltabdescrfile). The function Find_marks_and_pose extracts the marker points on the calibration plate and obtains their coordinates in the image coordinate system precisely. Above we have found the area of the calibration plate through the function Find_caltab, we first apply edge detection in this area (caltabregion) of the input image. This edge detection is controlled by the parameter alpha. The higher the alpha value, the higher the sensitivity of the edge detection, which will make the edge detection more detailed, but at the same time reduce the ability to suppress noise. In the edge image, a closed contour line is extracted. To find the contour line more accurately, a threshold operation is performed on the amplitude of the edge. All points with high amplitude (the boundary of the marked point) are selected. First, this threshold is set to Startthresh. If you look for a closed contour or an estimation of a pose failure, the threshold is reduced deltathresh until the threshold is lowered to the minimum value of Minthresh. The number of closed footprints must be the same as the number of marker points described in the Calibration board description file (caltabdescrfile), and the shapes of these closed footprints must be oval-shaped. If the length is shorter than the mincontlength contour line or contour line forming area of the diameter of large maxdiammarks (such as the outer frame of the calibration plate), these footprints will be ignored discarded.
Third, save the coordinate value
tmpctrl_allmarkrows: = []tmpctrl_allmarkcolumns: = []tmpctrl_startposes: = []tmpctrl_allmarkrows: = [Tmpctrl_allmarkrows, tmpctrl_markrows]tmpctrl_allmarkcolumns: = [Tmpctrl_allmarkcolumns, Tmpctrl_markcolumns]tmpctrl_startposes: = [tmpctrl_startposes, Tmpctrl_estimatedpose]
Notes: The coordinates of the fixed point in the image coordinate system are stored in two arrays, the first array stores the row coordinates of all points, the second array stores the column coordinates of all points, and the value one by one of the two arrays is guaranteed to correspond. The length of these arrays depends on the number of marked points on the calibration plate and the amount of calibrated images taken. The order in which they are stored is arranged in the order of the images, that is, the first m value stores the coordinate values of the M-labeled fixed points in the initial image, which is consistent with the order of storage in X, Y, Z of the array returned by the function caltab_points.
four, the camera calibration input parametersStartparameters: = [0.008,0,5.2e-006,5.2e-006,640,512,1280,1024] Initial camera calibration is a very complex nonlinear optimization problem, so you need to provide as much accurate initial values as possible for the camera's parameters. The initial values of the camera's internal parameters are determined primarily by the CCD sensor and the lens's specification. The reference initial value of the face array camera can be entered into an array [f,k,sx,sy,cx,cy,numcolumns,numrows] that is, not only to provide the camera's initial internal, but also to provide the image width (numcolumns) and High (numrows).
Five, determine the camera's internal, error analysis, operator is as followsCamera_calibration (:: Nx,ny,nz,nrow,ncol,startcamparam, Nstartpose,e Stimateparams:camparam,nfinalpose,errors)
The functions are as follows:caltab_points (' E:/calibration_description/caltab_123mm.descr ', tmpctrl_x, tmpctrl_y, TmpCtrl_Z)camera_calibration (tmpctrl_x, tmpctrl_y, Tmpctrl_z, Tmpctrl_allmarkrows, Tmpctrl_allmarkcolumns, Startparameters, tmpctrl_startposes, ' All ', Cameraparameters, tmpctrl_finalposes, tmpct Rl_errors)Given the initial value of the camera's internal and external parameters, the fixed point of the known three-dimensional position can be converted into the camera coordinate system. Then, the parameters of a set of cameras are sought to minimize the distance between the coordinates of the fixed point and the fixed point extracted directly from the image by calculating the coordinates projected onto the image. This minimized process will return a fairly accurate camera parameter. However, in order to obtain the highest accuracy camera parameters, you need to take a number of images of the calibration plate, when shooting, the calibration plate is placed in different positions of the image and the angle of rotation is different, so that the use of all degrees of freedom of the external orientation. If you take an image that contains a calibration plate, the most optimized parameters include the camera's internal reference and a set of external arguments. At this point, the goal of optimization is to determine that all of these parameters can meet the point coordinates computed by projection in each image and the minimum distance of the coordinate values extracted directly from the images. In Halcon, using the Camera_calibration function is the implementation of this function.
Select an image as a reference pose to determine the camera external parametersTmpctrl_referenceindex: = 0notes:Tmpctrl_referenceindex: The image that will be set as a reference bit pose. 0 represents the first one. 1 stands for the second one. And so onTuple_select_range (tmpctrl_finalposes, 7*tmpctrl_referenceindex, 7*tmpctrl_referenceindex + 6, CameraPose)set_origin_pose (camerapose, 0.0, 0.0, 0.001, camerapose)Note: tuple_select_range: Make array selections. Set_origin_pose: Calculates the camera external parameters.
Halcon Camera Calibration