1、halcon 自带例子详解
ImgPath := ‘3d_machine_vision/calib/’
dev_close_window ()
dev_open_window (0, 0, 652, 494, ‘black’, WindowHandle)
dev_update_off ()
dev_set_draw (‘margin’)
dev_set_line_width (3)
set_display_font (WindowHandle, 14, ‘mono’, ‘true’, ‘false’)
*
- Calibrate the camera.
- 生成初始内参
gen_cam_par_area_scan_division (0.016, 0, 0.0000074, 0.0000074, 326, 247, 652, 494, StartCamPar)
*创建CalibDataID(校准数据模型)
create_calib_data (‘calibration_object’, 1, 1, CalibDataID)
*将CalibDataID与StartCamPar(初始参数)绑定
set_calib_data_cam_param (CalibDataID, 0, [], StartCamPar)
*将CalibDataID中与caltab_30mm.descr(此文件与是根据校准板生成的)绑定(在“校准数据模型”中定义“校准对象”)
set_calib_data_calib_object (CalibDataID, 0, ‘caltab_30mm.descr’)
NumImages := 10 - Note, we do not use the image from which the pose of the measurement plane can be derived
for I := 1 to NumImages by 1
read_image (Image, ImgPath + ‘calib_’ + I$‘02d’)
dev_display (Image)
*寻找“校准板”
find_calib_object (Image, CalibDataID, 0, 0, I, [], [])
*获取“校准板”外部轮廓
get_calib_data_observ_contours (Caltab, CalibDataID, ‘caltab’, 0, 0, I)
dev_set_color (‘green’)
dev_display (Caltab)
endfor
*通过同时最小化过程确定所有相机参数,Error给出了优化是否成功的一般指示
calibrate_cameras (CalibDataID, Error)
*获取校准数据
get_calib_data (CalibDataID, ‘camera’, 0, ‘params’, CamParam) - Write the internal camera parameters to a file
write_cam_par (CamParam, ‘camera_parameters.dat’)
Message := ‘Interior camera parameters have’
Message[1] := ‘been written to file’
disp_message (WindowHandle, Message, ‘window’, 12, 12, ‘red’, ‘false’)
clear_calib_data (CalibDataID)
2、个人补充
camera_parameters.dat 是相机内参的保存文件,,利用write_cam_par进行保存,利用read_cam_par进行读取,数据类型 为 CameraParam。。
(1)可以利用gen_caltab (7, 7, 0.0125, 0.5, ‘caltab.descr’, ‘caltab.ps’) 来生成标定板描述文件caltab.descr,,和图形文件caltab.ps(可以用PS打开)
77 表示: 标定板有77 =49个点
0.0125 表示:每个圆心之间的距离为0.0125m,即12.5mm
0.5 表示 “圆心距离”与“圆心半径“的比值为0.5,即 圆的大小为12.5mm*0.5=6.25mm
(2)内参的使用方式
第一步: 调整内参
change_radial_distortion_cam_par (‘adaptive’, CameraParam, 0, CamParamOut)
第二步:生成map
gen_radial_distortion_map (Map, CameraParam, CameraParamOut, ‘bilinear’)
第三步 :图像转化
map_image (Image, Map, ImageMapped)
3、其他链接:
https://blog.csdn.net/cashmood/article/details/100089295