halcon标定详解
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
*创建标定板
gen_caltab(7,7,0.008,0.5,'48_48mm.descr','48_48mm.ps')
*=======标定内参
dev_close_window ()
dev_open_window (0, 0, 652, 494, 'black', WindowHandle)
dev_update_off ()
dev_set_draw ('margin')
dev_set_line_width (3)
OpSystem := environment('OS')
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
*标定相机
StartCamPar := [0.0,0.0,0.0000299,0.0000299,4896/2,3264/2,4896,3264] create_calib_data ('calibration_object', 1, 1, CalibDataID)
set_calib_data_cam_param (CalibDataID, 0, 'area_scan_telecentric_divi sion', StartCamPar)
set_calib_data_calib_object (CalibDataID, 0, '48_48mm.descr')
* Note, we do not use the image from which the pose of the measuremen t plane can be derived
for index := 1 to 13 by 1
read_image (Image, '标定20/' + index + '.png')
get_image_size(Image, Width, Height)
dev_display (Image)
find_calib_object (Image, CalibDataID, 0, 0, index, [], [])
get_calib_data_observ_contours (Caltab, CalibDataID, 'caltab', 0, 0, index)
dev_set_color ('green')
dev_display (Caltab)
endfor
calibrate_cameras (CalibDataID, Error)
get_calib_data (CalibDataID, 'camera', 0, 'params', CamParam)
get_calib_data (CalibDataID, 'calib_obj_pose', [0,1], 'pose', PoseCal ib)
*输出计算的相机内参
write_cam_par (CamParam, 'camera_parameters.dat')
Message:= '相机内参已经写入文件中'
disp_message (WindowHandle, Message, 'window', 12, 12, 'red', 'false ')
clear_calib_data (CalibDataID)
stop()
*=====标定外参
dev_set_draw ('margin')
dev_set_line_width (1)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
*从文件中读取内参存储文件:camera_parameters.dat
try
read_cam_par ('camera_parameters.dat', CamParam)
catch (Exception)
stop ()
endtry
*开始计算
open_file('data.csv','output', FileHandle)
fwrite_string(FileHandle,'Dis_pix*0.0299204,Dis_m*1000,Distance') fnew_line (FileHandle)
close_file(FileHandle)
*选择一张作为标定作为最终标定位姿(任意一张都可以)
index:=1
read_image (Image,'标定20/'+index+'.png')
dev_display (Image)
CaltabName := '48_48mm.descr'
create_calib_data ('calibration_object', 1, 1, CalibDataID)
* Here, the final camera parameters are already known and can be used instead
* of the starting values used in the program 'camera_calibration_inte rnal.hdev'
set_calib_data_cam_param (CalibDataID, 0, 'area_scan_telecentric_divi sion', CamParam)
set_calib_data_calib_object (CalibDataID, 0, CaltabName)
find_calib_object (Image, CalibDataID, 0, 0, 1, [], [])
get_calib_data_observ_contours (Caltab, CalibDataID, 'caltab', 0, 0, 1)
get_calib_data_observ_points (CalibDataID, 0, 0, 1, RCoord, CCoord, I ndex, PoseForCalibrationPlate)
dev_set_color ('green')
dev_display (Caltab)
dev_set_color ('red')