* 在执行此示例之前,必须执行示例'handeye_stationarycam_calibration.hdev'。
* 给定通过手眼校准计算的变换,该示例计算机器人工具在机器人基座坐标中的姿势,以便用夹具抓住螺母。
dev_update_off ()
dev_close_window ()
* 具有校准图像和数据文件的目录 Directories with calibration images and data files
ImageNameStart := '3d_machine_vision/handeye/stationarycam_'
DataNameStart := 'handeye/stationarycam_'
read_image (Image, ImageNameStart + 'nut12_square')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowHandle)
dev_set_draw ('margin')
dev_set_line_width (2)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_display (Image)
disp_message (WindowHandle, 'Object to grasp', 'window', 12, 12, 'black', 'true')
* 读取内部摄像头参数和校准姿势 Read internal camera parameters and calibrated poses
read_cam_par (DataNameStart + 'final_campar.dat', CamParam)//读相机参数
read_pose (DataNameStart + 'final_pose_cam_base.dat', BaseInCamPose)//读机器人基础坐标在相机坐标中姿
态参数
pose_to_hom_mat3d (BaseInCamPose, cam_H_base)//将姿态转为齐次变换矩阵
read_pose (DataNameStart + 'final_pose_tool_calplate.dat', CalplateInToolPose)//读机物体(标定板)在
工具坐标系下姿势
pose_to_hom_mat3d (CalplateInToolPose, tool_H_calplate)//将姿态转为齐次变换矩阵
* 在工具坐标中读取夹具的姿势 Read pose of gripper in tool coordinates
read_pose (DataNameStart + 'pose_tool_gripper.dat', GripperInToolPose)//读取抓手夹具在工具坐标中的姿
势()
pose_to_hom_mat3d (GripperInToolPose, tool_H_gripper)//将姿态转为齐次变换矩阵
stop ()
* 定义标定板姿势为参考坐标系并显示它 Define reference coordinate system and display it
CalplateFile := 'caltab_30mm.descr'
define_reference_coord_system (ImageNameStart + 'calib3cm_00', CamParam, CalplateFile, WindowHandle,
PoseRef)//显示标定板坐标系
pose_to_hom_mat3d (PoseRef, cam_H_ref)//标定板中心坐标系(该坐标系下的点乘以其可得到相机坐标系下对应
的点)
Message := '定义参考坐标系 Defining a reference coordinate system'
Message[1] := 'based on a calibration image'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_display (Image)
disp_3d_coord_system (WindowHandle, CamParam, PoseRef, 0.01)//继续显示标定板坐标系
* 找到螺母的平行边 Find parallel sides of the nut
dev_set_color ('yellow')
threshold (Image, BrightRegion, 60, 255)//阀值化
connection (BrightRegion, BrightRegions)//计算一个区域中联通的部分
select_shape (BrightRegions, Nut, 'area', 'and', 500, 99999)//根据特征选择区域
fill_up (Nut, NutFilled)//填充图像中各个区域的小孔,填充后区域的个数不变
gen_contour_region_xld (NutFilled, NutContours, 'border')//根据区域创建 XLD 轮廓(contour)