一、标定多圆孔标定
其理论与棋盘格 和圆孔都是一样的,不一样的地方就是定方向的方式不一样。如图
2、结果
read_image (CalibImage, './circle/1.png')
get_image_size (CalibImage, Width, Height)
dev_close_window ()
dev_open_window_fit_image (CalibImage, 0, 0, -1, -1, WindowHandle)* 助手标定
CameraParameters := ['area_scan_division',0.0191686,-293.693,8.49852e-06,8.5e-06,638.237,471.238,1292,964]
CameraPose := [-0.000160182,0.000890509,0.278671,0.341699,0.404851,0.60887,0]
stop ()* Calibration 01: Code generated by Calibration 01
ImageFiles := []
ImageFiles[0] := './circle/1.png'
ImageFiles[1] := './circle/2.png'
ImageFiles[2] := './circle/3.png'
ImageFiles[3] := './circle/4.png'
ImageFiles[4] := './circle/5.png'
read_image (Imageww, ImageFiles[0])get_image_size (Imageww, Width, Height)
TmpCtrl_ReferenceIndex := 0
TmpCtrl_PlateDescription := './circle/mycpd.cpd'StartParameters :=['area_scan_division',0.0191686,-293.693,8.49852e-06,8.5e-06,638.237,471.238,1292,964]
TmpCtrl_FindCalObjParNames := 'sigma'
TmpCtrl_FindCalObjParValues := 1
* Calibration 01: Create calibration model for managing calibration data
create_calib_data ('calibration_object', 1, 1, CalibHandle)
set_calib_data_cam_param (CalibHandle, 0, [], StartParameters)
set_calib_data_calib_object (CalibHandle, 0, TmpCtrl_PlateDescription)
* Calibration 01: Collect mark positions and estimated poses for all plates
for Index := 0 to |ImageFiles|-1 by 1read_image (Image, ImageFiles[Index])find_calib_object (Image, CalibHandle, 0, 0, Index, TmpCtrl_FindCalObjParNames, TmpCtrl_FindCalObjParValues)get_calib_data_observ_points (CalibHandle, 0, 0, 0, Row, Column, Index1, Pose)gen_cross_contour_xld (Cross, Row, Column, 6, 0.785398)disp_3d_coord_system (WindowHandle, CameraParameters, Pose, 0.01)
endfor
* Calibration 01: Perform the actual calibration
set_calib_data (CalibHandle, 'camera', 0, 'excluded_settings', [])
calibrate_cameras (CalibHandle, TmpCtrl_Errors)
*CameraParameters内参
get_calib_data (CalibHandle, 'camera', 0, 'params', CameraParameters)
get_calib_data (CalibHandle, 'calib_obj_pose', [0, TmpCtrl_ReferenceIndex], 'pose', CameraPose)
* Calibration 01: Adjust origin for plate thickness
*CameraPose外参
set_origin_pose (CameraPose, 0.0, 0.0, 0.003, CameraPose)
stop ()
* Calibration 01: Sample code generated by Calibration 01
* Calibration 01: For demonstration purposes, we use the calibration
* Calibration 01: plate itself as sample object.
* Calibration 01: Therefore, we load the reference image
stop ()
二、棋盘格映射矫正图像
思路与重点算子:
提取出棋盘格的角点
*算子saddle_points_sub_pix专为提取鞍点设计,即在一个方向上图像强度最小,在另一个方向上图像强度最大
saddle_points_sub_pix (ImageReduced, 'facet', SigmaSaddlePoints, Threshold, Row, Col)
*
使用标定棋盘,计算出map映射
* *确定图像映射
*根据规则网格的点计算畸变图像和校正图像之间的映射。
gen_grid_rectification_map (ImageReduced, ConnectingLines, Map, Meshes, GridSpacing, 0, Row, Col, 'bilinear')
map_image (ImageReduced, Map, ImageMapped)
使用map 矫正图像
* Read in the image to be rectified
read_image (Image, 'can')
*
* Rectify image using the previously calculated image map
dev_set_window (WindowID2)
map_image (Image, Map, ImageMapped)
三、矫正失真图像
原图
code
* This example illustrates how to use the operator gen_arbitrary_distortion_map.
*
GridSpacing := 50
*
dev_update_window ('off')
read_image (Image, 'calib/grid_space.cal.k.000')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width * 0.5, Height * 0.5, 'black', DistortedWindow)
set_display_font (DistortedWindow, 14, 'mono', 'true', 'false')
dev_set_part (0, 0, Height - 1, Width - 1)
dev_open_window (0, (Width * 0.5) + 12, 6 * GridSpacing, 6 * GridSpacing, 'black', RectifiedWindow)
set_display_font (RectifiedWindow, 14, 'mono', 'true', 'false')
*
gen_cam_par_area_scan_division (0.025, 0.0, 0.000011, 0.000011, 384.0, 288.0, 768, 576, StartCamParam)
* Make sure that the file 'CaltabDescrName' is in the current directory,
* the HALCONROOT/calib directory, or use an absolute path
CaltabDescrName := 'caltab_small.descr'
for I := 0 to 8 by 1dev_set_window (DistortedWindow)* 读取图像read_image (Image, 'calib/grid_space.cal.k.' + (I$'03'))dev_display (Image)* 找到标定台的地标find_caltab (Image, Caltab, CaltabDescrName, 3, 112, 5)* 找到标定台的地标和位姿find_marks_and_pose (Image, Caltab, CaltabDescrName, StartCamParam, 128, 10, 18, 0.9, 15, 100, RCoordTmp, CCoordTmp, StartPoseTmp)dev_set_color ('green')* Display centers of landmarks foundgen_cross_contour_xld (Cross, RCoordTmp, CCoordTmp, 12, 0.785398)dev_display (Cross)disp_message (DistortedWindow, 'Extracted marks in original image', 'window', 12, 12, 'black', 'true')* dev_set_window (RectifiedWindow)dev_set_part (1, 1, -1, -1)*gen_arbitrary_distortion_map —生成投影图,该投影图描述任意失真的图像和校正后的图像之间的映射gen_arbitrary_distortion_map (Map, GridSpacing, RCoordTmp, CCoordTmp, 7, Width, Height, 'bilinear')* map_image 重新投影map_image (Image, Map, ImageMapped)get_image_size (ImageMapped, MapWidth, MapHeight)dev_set_part (0, 0, MapHeight - 1, MapWidth - 1)dev_display (ImageMapped)disp_message (RectifiedWindow, 'Rectified grid', 'window', 12, 12, 'black', 'true')* if (I < 8)disp_continue_message (DistortedWindow, 'black', 'true')stop ()endif
endfor