halcon双目标定
*取消更新
dev_update_off ()
*获取窗体句柄
dev_get_window (WindowHandle)
*设置窗体字体样式
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
*设置线条粗细
dev_set_line_width (3)
*创建空对象
gen_empty_obj (ImageL)
*读取指定文件内子集
list_files ('G:/imageL', ['files','follow_links','recursive'], ImageFiles)
*筛选文件类型
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
*读取图像
read_image (Image, ImageFiles[Index])
*对象追加
concat_obj (ImageL, Image, ImageL)
endfor
*创建空对象
gen_empty_obj (ImageR)
*读取指定文件内子集
list_files ('G:/imageR', ['files','follow_links','recursive'], ImageFiles)
*筛选文件类型
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
*读取图像
read_image (Image, ImageFiles[Index])
*对象追加
concat_obj (ImageR, Image, ImageR)
endfor
*暂停程序
stop ()
Cameraparm:=['area_scan_division',0.008,0,3.2e-006,3.2e-006,1024,768,2048,1536]
*创建标定模型
create_calib_data ('calibration_object', 2, 1, CalibDataID)
*设置相机的初始内参
set_calib_data_cam_param (CalibDataID, 'all', [], Cameraparm)
*设置标定板的描述文件
set_calib_data_calib_object (CalibDataID, 0, 'G:/other/双相机标定描述文件.descr')
*对象计算
count_obj (ImageR, Number)
*打开一个窗体
dev_open_window (0, 0, 512, 512, 'black', WindowHandle1)
*打开一个窗体
dev_open_window (50, 50, 512, 512, 'black', WindowHandle2)
IndexL:=0
IndexR:=0
for I := 1 to Number by 1
*选择指定条件的对象
select_obj (ImageL, ObjectSelectedL, I)
*选择指定条件的对象
select_obj (ImageR, ObjectSelectedR, I)
*查找标定板
find_calib_object (ObjectSelectedL, CalibDataID, 0, 0, I, [], [])
*查找标定板
find_calib_object (ObjectSelectedR, CalibDataID, 1, 0, I, [], [])
*获取标定板mark点轮廓
get_calib_data_observ_contours (Contours, CalibDataID, 'marks', 0, 0, I)
*获取标定板mark点轮廓
get_calib_data_observ_contours (Contours1, CalibDataID, 'marks', 1, 0, I)
get_calib_data_observ_pose (CalibDataID, 0, 0, I, ObjInCameraPoseL)
get_calib_data_observ_pose (CalibDataID, 1, 0, I, ObjInCameraPoseR)
*获取标定板姿态和中心行列坐标
get_calib_data_observ_points (CalibDataID, 0, 0, I, Row, Column, Index2, Pose)
*获取标定板姿态和中心行列坐标
get_calib_data_observ_points (CalibDataID, 1, 0, I, Row1, Column1, Index3, Pose1)
dev_set_window (WindowHandle1)
*显示图像
dev_display (ObjectSelectedL)
*显示图像
dev_display (Contours)
*在区域中心点画十字叉
gen_cross_contour_xld (Cross, Row, Column, 16, 0.785398)
*显示图像
dev_display (Cross)
*显示3d坐标系
disp_3d_coord_system (WindowHandle1, Cameraparm, ObjInCameraPoseL, 0.05)
dev_set_window (WindowHandle2)
*显示图像
dev_display (ObjectSelectedR)
*显示图像
dev_display (Contours1)
*在区域中心点画十字叉
gen_cross_contour_xld (Cross1, Row1, Column1, 16, 0.785398)
*显示图像
dev_display (Cross1)
*显示3d坐标系
disp_3d_coord_system (WindowHandle2, Cameraparm, ObjInCameraPoseR, 0.05)
* stop ()
endfor
*暂停程序
stop ()
*反向均方差RMSE
calibrate_cameras (CalibDataID, Error)
*获得camera 内参,calib_obj_pose 外参
get_calib_data (CalibDataID, 'camera', 0, 'params', CameraparmL)
*获得camera 内参,calib_obj_pose 外参
get_calib_data (CalibDataID, 'camera', 1, 'params', CameraparmR)
*获得camera 内参,calib_obj_pose 外参
get_calib_data (CalibDataID, 'camera', 1, 'pose', LHR)
*获得camera 内参,calib_obj_pose 外参
get_calib_data (CalibDataID, 'calib_obj_pose', [0,1], 'pose', LHO1)
*姿态翻转
pose_invert (LHR, RHL)
*姿态相乘
pose_compose (RHL, LHO1, RH01)
dev_set_window (WindowHandle1)
*读取图像
read_image (Image01, 'G:/imageL/image_01.png')
*显示图像
dev_display (Image01)
dev_set_window (WindowHandle2)
*读取图像
read_image (Image02, 'G:/imageR/image_01.png')
*显示图像
dev_display (Image02)
*转世界坐标
image_points_to_world_plane (CameraparmL,LHO1,819, 597, 'm', X, Y)
*转世界坐标
image_points_to_world_plane (CameraparmR, RH01, 976, 1615, 'm', X1, Y1)
*求两个坐标的直线距离
distance_pp (X, Y, X1, Y1, Distance)
*设置窗体字体样式
set_display_font (WindowHandle2, 16, 'mono', 'true', 'false')
*显示文本
disp_message (WindowHandle2, '边长:'+(Distance*1000)$'4.2f'+'mm', 'image', 0, 0, 'red', 'true')