此示例显示如何基于由SCARA手眼校准确定的校准信息,使用SCARA机器人执行拾取和放置应用程序。 在第一步骤中,根据模型图像定义形状模型。 然后,基于该形状模型,在每个图像中搜索对象。 对于一个选定的对象,计算可用于掌握该对象的机器人坐标。 为了使该示例适用于实际应用,必须从相机获取图像(而不是从文件读取),并且必须实施机器人的控制(而不是在本示例中被注释掉的相应行)。 通常,图像必须在匹配之前校正。 如果摄像机完全正交于测量平面,则此步骤可以仅被省略。 要使用提供的示例图像运行示例程序,RectifyImages必须设置为true。

RectifyImages := true

try
  //读取手眼校正的结果
  read_pose ('cam_in_base_pose.dat', CamInBasePose)
  read_cam_par ('camera_parameters.dat', CameraParam)
  //读取要抓取的对象的姿态估计所需要的参数
  read_pose ('measurement_plane_in_cam_pose.dat', MPInCamPose)
catch (Exception) 
  CamInBasePose:=[0.05592166548,0.19497621789,0.48025117245,180.09816119,29.85593363,179.94389014,] 
  CameraParam := [0.0165251,-642.277,.65521e-,.65e-,595.817,521.75,,  ]
  MPInCamPose := [0.0045679683065,-0.0028695297318,0.4088853425,359.78658429,29.7320275  ,0.22946472765,]
endtry
//准备校准map以消除图像的失真
if (RectifyImages)
  prepare_rectification_map (Map, CameraParam, MPInCamPose, MappingScale,MPInCamPoseMapping)
  image_points_to_world_plane (CameraParam, MPInCamPoseMapping, , , 'm',MapUpperLeftX, MapUpperLeftY)
endif
dev_update_off ()
set_system ('border_shape_models', 'true')
//这里,应该建立与机器人的连接,并且机器人应该移动到一个定义的待机姿态,允许获取测量平面的未被遮挡的图像
//定义要抓取的对象形状模型
//获取模型的图像
read_image (Image, '3d_machine_vision/handeye/scara_stationary_cam_setup_01_metal_parts_01')
if (RectifyImages)
  map_image (Image, Map, ModelImage)
else
  copy_image (Image, ModelImage)
endif
dev_close_window ()
dev_open_window_fit_image (ModelImage, , , , , WindowHandle)
set_display_font (WindowHandle, , 'mono', 'true', 'false')
dev_clear_window ()
dev_display (ModelImage)
dev_set_line_width ()
//创建形状模型
gen_rectangle1 (ModelROI, , , , )
gauss_filter (ModelImage, ImageGauss, )
reduce_domain (ImageGauss, ModelROI, ImageReduced)
create_shape_model (ImageReduced, 'auto', rad(), rad(), 'auto', 'auto', 'use_polarity', [,], 'auto', ModelID)
area_center (ModelROI, ModelROIArea, ModelROIRow, ModelROIColumn)
dev_display_shape_matching_results (ModelID, 'green', ModelROIRow, ModelROIColumn, , , , )
//指定对象的抓取点
//它要在图像中(只有当对象可以由工具以任何方向拾取时)
//或者通过用机器人抓取它并记录相应的机器人姿态
DefineGraspingPointByRobot := true
if (DefineGraspingPointByRobot)
  dev_set_colored ()
  GraspingPointModelInBasePose := [0.2592,0.1997,0.1224,,,1.2572,] 
  pose_invert (CamInBasePose, BaseInCamPose)
  pose_to_hom_mat3d (BaseInCamPose, BaseInCamHomMat3D)
  affine_trans_point_3d (BaseInCamHomMat3D,GraspingPointModelInBasePose[], GraspingPointModelInBasePose[], GraspingPointModelInBasePose[], Qx, Qy, Qz)
  project_3d_point (Qx, Qy, Qz, CameraParam, GraspingPointModelRow,GraspingPointModelColumn)
  GraspingPointModelAngle := GraspingPointModelInBasePose[]
  if (RectifyImages)
    //计算校正图像坐标   
    image_points_to_world_plane (CameraParam, MPInCamPoseMapping, GraspingPointModelRow, GraspingPointModelColumn, MappingScale, GraspingPointModelXMP, GraspingPointModelYMP)    
    GraspingPointModelRow := GraspingPointModelYMP - MapUpperLeftY / MappingScale    
    GraspingPointModelColumn := GraspingPointModelXMP - MapUpperLeftX / MappingScale    
    //在以校正模型图片中显示抓取点
    get_image_size (ModelImage, WidthM, HeightM)
    CamParamRect := [,,MappingScale,MappingScale,-MapUpperLeftX / MappingScale,-MapUpperLeftY / MappingScale,WidthM,HeightM]   
    GraspingPointModelXMP := MapUpperLeftX + GraspingPointModelColumn * MappingScale
    GraspingPointModelYMP := MapUpperLeftY + GraspingPointModelRow * MappingScale    
    PoseCoordSystemVis :=     [GraspingPointModelXMP,GraspingPointModelYMP,,,,GraspingPointModelA    ngle,]    
    dev_set_colored ()
    disp_3d_coord_system (WindowHandle, CamParamRect,PoseCoordSystemVis, 0.02)  
  else
    //在原始模型图像中显示抓取点
    pose_invert (CamInBasePose, BaseInCamPose)
    pose_compose (BaseInCamPose, GraspingPointModelInBasePose,PoseCoordSystemVis)
    dev_set_colored ()
    disp_3d_coord_system (WindowHandle, CameraParam,PoseCoordSystemVis, 0.02)
  endif  
  disp_message (WindowHandle, 'Model contours and grasping pose', 'window',   , , 'black', 'true')
else
  binary_threshold (ImageReduced, Region, 'max_separability', 'light',   UsedThreshold)
  fill_up (Region, RegionFillUp)
  erosion_rectangle1 (RegionFillUp, RegionErosion, , )
  smallest_rectangle2 (RegionErosion, GraspingPointModelRow,GraspingPointModelColumn, Phi, Length1, Length2)
  gen_cross_contour_xld (GraspingPointModel, GraspingPointModelRow,GraspingPointModelColumn, , 0.785398)
  dev_set_color ('yellow')
  dev_display (GraspingPointModel)
  disp_message (WindowHandle, 'Model contours and grasping point', 'window',, , 'black', 'true')
endif
area_center (ModelROI, ModelROIArea, ModelROIRow, ModelROIColumn)
set_shape_model_origin (ModelID, GraspingPointModelRow - ModelROIRow, GraspingPointModelColumn - ModelROIColumn)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
pose_to_hom_mat3d (MPInCamPoseMapping, MPInCamHomMat3DMapping)
//在下列图像中找被抓取的物体
for ImageIdx := to by 1
  //下一幅图片
  read_image (Image,'3d_machine_vision/handeye/scara_stationary_cam_setup_01_metal_parts_' +ImageIdx$'02d')  
  //校正图片来适应标准模型的匹配
//寻找实例
  if (RectifyImages)
    map_image (Image, Map, SearchImage)
  else
    copy_image (Image, SearchImage)
  endif
  dev_clear_window ()
  dev_display (SearchImage)
  //寻找物体实例  
  find_shape_model (SearchImage, ModelID, rad(), rad(), 0.5, , 0.5,   'least_squares', [,], 0.9, Row, Column, Angle, Score)  
  if (|Row| < )
    disp_message (WindowHandle, 'No objects found', 'window', , , 'black',     'true')
    continue
  endif
  //选择一个指定的实例,这儿是最左边的  
  LeftmostIdx := sort_index(Column)[]
  GraspingPointRow := Row[LeftmostIdx]  
  GraspingPointColumn := Column[LeftmostIdx]
  GraspingPointAngle := Angle[LeftmostIdx]
  //显示匹配结果和指出要抓取的物体
  dev_display_shape_matching_results (ModelID, 'blue', Row, Column, Angle, , , )
  dev_display_shape_matching_results (ModelID, 'green', GraspingPointRow, GraspingPointColumn, GraspingPointAngle, , , )
  disp_message (WindowHandle, |Row| + ' objects found (Green: Object to be grasped)', 'window', , , 'black', 'true')
  disp_continue_message (WindowHandle, 'black', 'true')
  stop()
  //计算需要靠近的点
  calculate_point_to_approach_scara_stationary (GraspingPointRow, GraspingPointColumn, GraspingPointAngle + rad(GraspingPointModelAngle), RectifyImages, MapUpperLeftX, MapUpperLeftY, MappingScale, MPInCamHomMat3DMapping, CameraParam, MPInCamPose, CamInBasePose, ObjInBasePose)
  //显示要被抓取的物体和抓取点
  dev_clear_window ()
  dev_display (SearchImage)
  dev_display_shape_matching_results (ModelID, 'green', GraspingPointRow, GraspingPointColumn, GraspingPointAngle, , , )
  dev_set_colored ()
  if (RectifyImages)  
    get_image_size (SearchImage, Width, Height)
    CamParamRect := [,,MappingScale,MappingScale,-MapUpperLeftX / MappingScale,-MapUpperLeftY / MappingScale,Width,Height]
    GraspingPointXMP := MapUpperLeftX + GraspingPointColumn * MappingScale
    GraspingPointYMP := MapUpperLeftY + GraspingPointRow * MappingScale
    PoseCoordSystemVis := [GraspingPointXMP,GraspingPointYMP,,,,-deg(GraspingPointAngle) + GraspingPointModelAngle,]
    disp_3d_coord_system (WindowHandle, CamParamRect, PoseCoordSystemVis, 0.02)
  else
    pose_invert (CamInBasePose, BaseInCamPose)
    pose_compose (BaseInCamPose, ObjInBasePose, PoseCoordSystemVis)
    disp_3d_coord_system (WindowHandle, CameraParam, PoseCoordSystemVis, 0.02)
  endif
  disp_message (WindowHandle, 'Press F5 to pick and place indicated object', 'window', , , 'black', 'true')
  disp_message (WindowHandle, ['ObjInBasePose:','Tx: ','Ty: ','Tz: ','Alpha: ','Beta: ','Gamma: '] + ['',ObjInBasePose[:]$'.3f' + [' m',' m',' m',' deg',' deg',' deg']], 'window', , , 'black', 'true')
  disp_continue_message (WindowHandle, 'black', 'true')
  stop ()
  //转换目标位置为mm
  ToolInBasePoseMM := [ObjInBasePose[:] * ,ObjInBasePose[:]]
  //抓取和放置物体
endfor
//这儿机器人连接被关闭
clear_shape_model (ModelID)
set_system ('border_shape_models', 'false')
dev_clear_window ()

Halcon pick_and_place_scara_stationary_cam.hdev程序学习的更多相关文章

  1. 通过反汇编C语言小程序学习Liunx汇编语言

    大家好!    我是来自山东师范大学的吴乐.    今天在<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 ...

  2. Halcon的应用程序 打开后 弹出没有帮助文件错误提示

    问题: Halcon的应用程序 打开后 弹出没有帮助文件错误提示 解决方法: 建立(C:\ProgramFiles\MVTec\halcon)目录,将halcon安装目录下的help文件夹复制过来即可 ...

  3. 微信小程序 学习资料

    微信小程序 学习资料 资料名称 网址 官方教程 https://developers.weixin.qq.com/miniprogram/dev/index.html?t=18110517

  4. Tuxedo安装、配置、以及演示样例程序 (学习网址)

    Tuxedo安装.配置.以及演示样例程序 (学习网址): 1.http://liu9403.iteye.com/blog/1415684 2.http://www.cnblogs.com/fnng/a ...

  5. Java开发桌面程序学习(一)——JavaFx+Jfoenix初始以及搭建

    Java开发桌面程序学习(一)--JavaFx+Jfoenix初始以及搭建 前言 想做一个Java的桌面程序,但是,使用原生的Swing感觉又十分麻烦,那个布局都是拿代码设置,看着十分的乱,偶然的情况 ...

  6. 【微信小程序学习笔记】入门与了解

    [微信小程序学习笔记(一)] IDE 下载安装 下载地址 官方工具:https://mp.weixin.qq.com/debug/w … tml?t=1476434678461 下载可执行文件后,可按 ...

  7. 微信小程序学习笔记二 数据绑定 + 事件绑定

    微信小程序学习笔记二 1. 小程序特点概述 没有DOM 组件化开发: 具备特定功能效果的代码集合 体积小, 单个压缩包体积不能大于2M, 否则无法上线 小程序的四个重要的文件 *js *.wxml - ...

  8. 微信小程序学习笔记一 小程序介绍 & 前置知识

    微信小程序学习笔记一 1. 什么是小程序? 2017年度百度百科十大热词之一 微信小程序, 简称小程序, 英文名 Mini Program, 是一种不需要下载安装即可使用的应用 ( 张小龙对其的定义是 ...

  9. 【C#】1.3 WPF应用程序学习要点

    分类:C#.VS2015 创建日期:2016-06-14 使用教材:十二五国家级规划教材<C#程序设计及应用教程>(第3版) 一.要点概述 <C#程序设计及应用教程>(第3版) ...

随机推荐

  1. 白皮 Chapter 2

    7.2 做题一遍就过的感觉简直太美好啦~然而我并没有测试数据QAQ //program name digit #include<cstdio> #include<iostream&g ...

  2. AAS代码运行-第11章-1

    启动PySpark export IPYTHON= # PySpark也可使用IPython shell pyspark --master yarn --num-executors 发生如下错误: / ...

  3. JS技术大全

    事件源对象:event.srcElement.tagName  event.srcElement.type 捕获/释放:event.srcElement.setCapture();  event.sr ...

  4. Visual Studio 下C#编译器在解析属性名时如果增加一个get_[您的另一个已经包含在类中属性名]的属性会报错,微软大哥这是什么鬼?

    假设在在我们的vs环境新建一个类 copy以下代码,表面看好像一切都没有问题. using System; using System.Collections.Generic; using System ...

  5. CSS之过渡简单应用—日落西山

    代码: <!DOCTYPE html><html><head> <title>日落西山</title> <meta charset=& ...

  6. Percona Server 5.6.33-79.0 发布

    Percona Server 5.6.33-79.0 发布了,该版本基于 MySQL 5.6.33,包含了所有的 bug 修复,是Percona Server 5.6 系列中的正式版本.该版本主要是修 ...

  7. sql转db,后台坑货

    打开 创建一个db文件然后点击文件--新建---Sqlite 导入空db成功后点击左侧栏 点击表 点击右上角+号把sql文件的语句复制粘贴到 然后点击运行,运行完成后保存ok

  8. Spark源码学习1.8——ShuffleBlockManager.scala

    shuffleBlockManager继承于Logging,参数为blockManager和shuffleManager.shuffle文件有三个特性:shuffleId,整个shuffle stag ...

  9. C语言程序设计第六次作业

    同学们,本周我们已经学完了顺序结构.选择结构和循环结构,你都理解并掌握了吗?现在就好好理理思路,做个阶段总结吧.本周的知识点总结要求大家在理解的基础上对结构化程序设计的三种基本结构做一个全面的总结. ...

  10. Linq学习总结2--Linq to XML

    概述: linq to xml(下面简称ltx好了),是微软根据linq技术对于XML的CURD.使用起来比System.XML中的XML操作方式更加简便.这段时间使用它在公司里升级了老板的邮件系统, ...