Halcon 3D 手眼标定

c 复制代码
dev_update_off ()
dev_set_color ('green')
* Open a window if the correct size.
dev_close_window ()
WindowWidth := 512
WindowHeight := 384
* Directories containing images and data files.
ImagesDir := '3d_machine_vision/hand_eye/robot_gripper_gray_'
dev_open_window (0, WindowWidth + 10, WindowWidth, WindowHeight, 'black', ImageWindowHandle)
dev_open_window (0, 0, WindowWidth, WindowHeight, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
set_display_font (ImageWindowHandle, 14, 'mono', 'true', 'false')
Instruction := ['Rotate: Left button','Zoom:   Shift + left button','Move:   Ctrl  + left button']
*1.读取点云模型
read_object_model_3d ('hand_eye/robot_gripper_3d_model.om3', 1, [], [], OM3DModel, Status)
*创建点云模型
create_surface_model (OM3DModel, 0.03, [], [], SurfaceModelID)
Message := 'Surface model to be searched'
*显示点云模型
sample_object_model_3d (OM3DModel, 'fast', 0.0009, [], [], SampledObjectModel3D)
visualize_object_model_3d (WindowHandle, SampledObjectModel3D, [], [], 'color_0', 'gray', Message, [], Instruction, PoseOut)
* The number of files.
NumCalibrationScenes := 15
* 创建手眼标定模型,同时多个角度匹配事实的点云数据
create_calib_data ('hand_eye_stationary_cam', 0, 0, HECCalibDataID)
* 设置优化速度
set_calib_data (HECCalibDataID, 'model', 'general', 'optimization_method', 'nonlinear')

for I := 1 to NumCalibrationScenes by 1
    read_image (ImageRobotGripperGray, ImagesDir + I$'02d')
    * 读取位姿,工具坐标相对于机器人坐标的姿态
    *read_pose ('tool_in_base_pose_' + I$'02d' + '.dat', ToolInBasePose)
     read_pose('C:/Users/Public/Documents/MVTec/HALCON-17.12-Progress/examples/hdevelop/Calibration/Hand-Eye/tool_in_base_pose_'+ I$'02d' + '.dat',ToolInBasePose)
     *物体相对于传感器的位姿
    filename := 'hand_eye/robot_gripper_3d_scene_' + I$'02d'
    *读取模型
    read_object_model_3d (filename, 1, [], [], OM3DScene, Status1)
 
    find_surface_model (SurfaceModelID, OM3DScene, 0.05, 1, 0, 'false', [], [], ObjInCamPose, Score, SurfaceMatchingResultID)
    refine_surface_model_pose (SurfaceModelID, OM3DScene, ObjInCamPose, 0, 'false', [], [], ObjInCamPose, Score, SurfaceMatchingResultID1)
    if (|Score|)
         *如果有得分设置到模型里面
      
        set_calib_data (HECCalibDataID, 'tool', I, 'tool_in_base_pose', ToolInBasePose)
        set_calib_data_observ_pose (HECCalibDataID, 0, 0, I, ObjInCamPose)
    endif
    *仿射运算显示
    pose_to_hom_mat3d (ObjInCamPose, HomMat3D)
    affine_trans_object_model_3d (SampledObjectModel3D, HomMat3D, OM3DModelTrans)
    *显示场景图片
      if (I < 4)
        * Clear both windows.
        dev_clear_window ()
        dev_set_window (ImageWindowHandle)
        dev_display (ImageRobotGripperGray)
        disp_message (ImageWindowHandle, 'Image from pinhole camera', 'window', 12, 12, 'black', 'true')
        dev_set_window (WindowHandle)
        Message := 'Surface model is matched in the 3D scene.'
        Message[1] := 'Points of the current scene are gray.'
        Message[2] := 'Points of the matched model are green.'
        * For better visualization, reduce the point density of the model.
        sample_object_model_3d (OM3DScene, 'fast', 0.0009, [], [], SampledOM3DScene)
        disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
        Message := 'Scene: '
        Message[1] := I + ' of ' + NumCalibrationScenes
        disp_message (WindowHandle, Message, 'window', 80, 12, 'white', 'false')
        * Visualize matching result with user interaction.
        visualize_object_model_3d (WindowHandle, [SampledOM3DScene,OM3DModelTrans], [], [], ['color_0','color_1','disp_background'], ['gray','green','true'], [], [], Instruction, PoseOut)
      endif
   
endfor
clear_object_model_3d ([OM3DScene,OM3DModelTrans,SampledOM3DScene])
* 3 手眼标定
calibrate_hand_eye (HECCalibDataID, HECPoseError)
* 4.获取姿态
* 基础坐标系对于传感器(机械手)的姿态
get_calib_data (HECCalibDataID, 'camera', 0, 'base_in_cam_pose', BaseInSensorPose)
* 物体相对于传感器的姿态
get_calib_data (HECCalibDataID, 'calib_obj', 0, 'obj_in_tool_pose', ObjInToolPose)
相关推荐
鹧鸪云光伏4 分钟前
光伏无人机3D建模:毫秒级精度设计
3d·无人机
杀生丸学AI2 小时前
【三维生成】FlashDreamer:基于扩散模型的单目图像到3D场景
人工智能·3d·大模型·aigc·蒸馏与迁移学习·扩散模型与生成模型
gis分享者17 小时前
学习threejs,使用自定义GLSL 着色器,生成漂流的3D能量球
3d·threejs·着色器·glsl·shadermaterial·能量球
m0_7431064618 小时前
【论文笔记】BlockGaussian:巧妙解决大规模场景重建中的伪影问题
论文阅读·计算机视觉·3d·aigc·几何学
向宇it1 天前
【unity小技巧】在 Unity 中将 2D 精灵添加到 3D 游戏中,并实现阴影投射效果,实现类《八分旅人》《饥荒》等等的2.5D游戏效果
游戏·3d·unity·编辑器·游戏引擎·材质
荔枝味啊~2 天前
相机位姿估计
人工智能·计算机视觉·3d
在下胡三汉2 天前
什么是 3D 文件?
3d
点云登山者3 天前
登山第二十六梯:单目3D检测一切——一只眼看世界
3d·3d检测·检测一切·单目3d检测
xhload3d3 天前
智慧航天运载体系全生命周期监测 | 图扑数字孪生
物联网·3d·智慧城市·html5·webgl·数字孪生·可视化·工业互联网·三维建模·工控·航空航天·火箭升空·智慧航空·智慧航天·火箭发射·火箭回收
小赖同学啊3 天前
光伏园区3d系统管理
前端·javascript·3d