1. Understand the parameters of the calibration plate
- How should we use a calibration board or know its relevant parameters? If you use a standard dot calibration board, you can refer to this blog: Basic calibration process of Halcon circular calibration plate - Calibration assistant operation
- But like the rectangular calibration plate below, there is no standard information on it, so we need to measure it ourselves. The most important parameters we want to measure are point spacing and point diameter. Either a scale or a vernier caliper can be used. The accuracy of the measuring tool is not important because the probability of point spacing and point diameter of the calibration plate is a regular number.
- For example, we use a scale to measure from top to bottom, and then count the total distance, so that we can calculate the point distance. For the calibration plate below, the longitudinal point spacing of large diameter dots is 8mm, the transverse point spacing is 4mm, and the diameter of large dots is 2mm. With these parameters, we can use it to calibrate the pixel equivalent of the camera.
2. Determine the calibration method
- First of all, it must be noted that the pixel equivalent calibrated by the calibration plate is only for a certain plane, and the lens distortion is ignored. If the relative distance between the measured plane and the camera changes, the pixel equivalent will fail.
- Secondly, it should be noted that the pixel equivalent of the calibrated row direction and column direction is not equal. The reason is very simple, because you can't make the camera completely perpendicular to the plane. Sometimes the camera will be installed obliquely, but as long as we calibrate the pixel equivalent in the corresponding direction, there will be no problem using it to measure the size. (for example, when taking pictures of people, squatting down and taking pictures from bottom to top will make people's legs longer, because the pixel equivalent in the longitudinal direction is larger)
- As an example of calibration, the calibration plate is partially blocked, but this does not affect the calibration.
- The idea of calibration is: taking pictures - dividing dots - calculating the number of rows and columns of dots - calculating the pixel equivalent
3. Halcon code example
read_image (Cal, 'b1')
DotCalibrationPlate (Cal, RegionUnion, pixelAccuracyX, pixelAccuracyY)
dev_display (Cal)
dev_display (RegionUnion)
disp_message (3600, 'X Directional pixel equivalent:'+pixelAccuracyX, 'window', 12, 12, 'black', 'true')
disp_message (3600, 'Y Directional pixel equivalent:'+pixelAccuracyY, 'window', 42, 12, 'black', 'true')
*Cut the dot area on the calibration plate
threshold (Cal, Regions, 0, 154)
connection (Regions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions1, 'area', 'and', 1000, 3000)
fill_up (SelectedRegions1, RegionFillUp)
select_shape (RegionFillUp, SelectedRegions2, 'roundness', 'and', 0.73303, 1)
union1 (SelectedRegions2, RegionUnion)
shape_trans (RegionUnion, RegionTrans, 'convex')
inner_rectangle1 (RegionTrans, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
dilation_rectangle1 (Rectangle, RegionDilation, 200, 200)
reduce_domain (Cal, RegionDilation, ImageReduced)
*Calculate the length and width of the area composed of dots
threshold (ImageReduced, Regions, 0, 154)
connection (Regions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions1, 'area', 'and', 1000, 3000)
fill_up (SelectedRegions1, RegionFillUp)
select_shape (RegionFillUp, SelectedRegions2, 'roundness', 'and', 0.73303, 1)
count_obj (SelectedRegions2, PointNum)
colNum:=5
RowNum:=PointNum/colNum
union1 (SelectedRegions2, RegionUnion)
smallest_rectangle2 (RegionUnion, Row, Column, Phi, Length1, Length2)
*Judge the placement angle of the calibration board. If the angle is too much, exit the calibration
if (abs(abs(deg(Phi)) - 90) < 5)
LX:=4*(colNum-1)+2
LY:=8*(RowNum-1)+2
pixelAccuracyX:=LX/(Length2*2)
pixelAccuracyY:=LY/(Length1*2)
else
pixelAccuracyX:=0
pixelAccuracyY:=0
endif
return ()