对应示例程序:
apply_distance_transform_xld.hdev

目标: 比较算子distance_contours_xld 和算子 apply_distance_transform_xld的区别
一般情况下,在求解轮廓之间的距离时,distance_contours_xld都适用。但是对于参考XLD轮廓保持不变,被多次使用时,算子apply_distance_transform_xld可以缩短计算时间

思路为:
      1.读入图像,并利用算子edges_sub_pix提取出亚像素边缘。
      2.将原始图像进行算法弯曲,再利用算子edges_sub_pix得到弯曲后的亚像素边缘
      3. 利用算子distance_contours_xld 计算两个轮廓之间的距离,并计时
      4.利用算子create_distance_transform_xld 和pply_distance_transform_xld计算两个轮廓之间的距离,并计时
      5.显示算子运行的时间

图像:


代码:

* Init visualization
dev_close_window ()
dev_open_window_fit_size (0, 0, 1280, 1024, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
*
* Show introduction
Message := 'This example shows the speed difference between the operators'
Message[1] := 'distance_contours_xld and apply_distance_transform_xld.'
Message[2] := 'Both operators measure the pointwise distance between'
Message[3] := 'two contours.'
Message[4] := ' '
Message[5] := 'While distance_contours_xld can always be used,'
Message[6] := 'apply_distance_transform_xld is used if one of the contours'
Message[7] := 'is reused many times as an unchanging reference contour.'
Message[10] := 'In that case some time-consuming calculations can be done'
Message[11] := 'offline in advance so that apply_distance_transform_xld is'
Message[12] := 'much faster.'
disp_message (WindowHandle, Message, 'window', 12, 12, 'white', 'false')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Choose one of two modes.
* 'point_to_point' is faster,
* 'point_to_segment' is more accurate.
Mode := 'point_to_point'
* Mode := 'point_to_segment'
Tolerance := 7
Loops := 4
Legend := ['Legend:','- template contour','- random test contour within tolerance','- random test contour outside of tolerance']
*
* PART I: distance_contours_xld
*
*    distance_contours_xld calculates
*    the pointwise distance between two contours
*
for I := 1 to Loops by 1* Generate the two contours to be compared  生成测试轮廓gen_test_contours (EdgeOriginal, EdgeWarped)* Calculate pointwise distance.* The distances from points of the first to the points of the second contour* are stored in the 'distance' attribute of the output contour.* Parts of the contour can be easily segmented based on the attributes.count_seconds (S1)distance_contours_xld (EdgeWarped, EdgeOriginal, EdgeWarpedWithDistances, Mode)  //计算从一个轮廓到另一个轮廓的点距离。count_seconds (S2)get_contour_attrib_xld (EdgeWarpedWithDistances, 'distance', Distance)  //返回XLD轮廓的相关属性值//根据参数条件,分离XLD轮廓segment_contour_attrib_xld (EdgeWarpedWithDistances, ContourPart, 'distance', 'and', Tolerance, 99999)* display_result (EdgeOriginal, EdgeWarped, ContourPart) //显示Message := 'Part 1: Calculate distances with distance_contours_xld'Message[1] := 'Execution time: ' + ((S2 - S1) * 1000)$'.2f' + ' ms'disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')disp_message (WindowHandle, Legend, 'image', 800, 12, ['grey','white','green','red'], 'false')disp_continue_message (WindowHandle, 'black', 'true')stop ()
endfor
*
* PART II: apply_distance_transform_xld
*
*    apply_distance_transform_xld is used to calculate the
*    pointwise distance to changing contours to a not
*    changing reference contour.
*    To accelerate the calculation, some information is
*    pre-calculated and stored in a distance transform handle.
*
dev_clear_window ()
disp_message (WindowHandle, 'Please wait while pre-calculating distance transform...', 'window', 42, 12, 'white', 'false')
*
* Pre-calculate distance transform for the template contour
* (this may take a while, depending on the size of the contour
* and MaxDistance)
* The parameter MaxDistance is used to restrict the pre-calculated
* distance transform to the specified value. Distances larger than
* MaxDistance will not be calculated. Instead, the distances are
* clipped.
MaxDistance := 8
create_distance_transform_xld (EdgeOriginal, Mode, MaxDistance, DistanceTransformID)  //建参考轮廓Contour 的XLD距离转换,并在DistanceTransformID中返回结果句柄。
for I := 1 to Loops by 1gen_test_contours (NotUsedOriginal, TestContour)count_seconds (S1)apply_distance_transform_xld (TestContour, TestContourOut, DistanceTransformID) //使用XLD距离变换确定两个轮廓的点距离count_seconds (S2)* Note, that the calculated distances are clipped at MaxDistanceget_contour_attrib_xld (TestContourOut, 'distance', DistanceClipped) //返回XLD轮廓的相关属性值segment_contour_attrib_xld (TestContourOut, ContourPart, 'distance', 'and', Tolerance, MaxDistance) //根据参数分离XLD轮廓* display_result (EdgeOriginal, TestContour, ContourPart)  //显示结果Message := 'Part 2: Calculate distances with apply_distance_transform_xld'Message[1] := 'Execution time: ' + ((S2 - S1) * 1000)$'.2f' + ' ms'disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')disp_message (WindowHandle, Legend, 'image', 800, 12, ['grey','white','green','red'], 'false')if (I < Loops)disp_continue_message (WindowHandle, 'black', 'true')stop ()endifdump_window (WindowHandle, 'jpg', 'C:/Users/Bryce/Desktop/新建位图图像')
endfor
stop ()
clear_distance_transform_xld (DistanceTransformID) //释放句柄

用到的几个算子:
      real_to_vector_field --将两幅实值图像转换成矢量场图像。
      unwarp_image_vector_field-- 用矢量场解压图像
      add_noise_white–向图像添加噪声
      distance_contours_xld --计算从一个轮廓到另一个轮廓的点距离。
      create_distance_transform_xld --建参考轮廓Contour 的XLD距离转换,并在DistanceTransformID中返回结果句柄。
      apply_distance_transform_xld --使用XLD距离变换确定两个轮廓的点距离
      get_contour_attrib_xld --返回XLD轮廓的相关属性值
      segment_contour_attrib_xld --根据参数分离XLD轮廓
      clear_distance_transform_xld --释放XLD距离变换句柄

参考资料:
[1]:https://www.gkbc8.com/forum.php?mod=viewthread&ordertype=1&tid=13765

二维测量--轮廓间的距离相关推荐

  1. 【ABviewer从零开始教学查看器篇⑥】二维测量和三维测量

    ABViewer是一款高质量.高效率.低成本的多功能设计及工程文档管理工具,能为您提供全面的专业的浏览及编辑功能,同时支持30多种光栅和矢量图形格式. 在小编看来,ABViewer是一款非常简单且实用 ...

  2. Matlab中矩阵编号方式以及一维二维三维数据间的相互转换

    Matlab中矩阵编号方式以及一维二维三维数据间的相互转换 文章目录 Matlab中矩阵编号方式以及一维二维三维数据间的相互转换 一.问题的提出 二.一维数据转为二维和三维 三.三维数据转为一维和二维 ...

  3. 基于遗传算法的二维最大类间方差法的图像分割优化

    一.背景 最大类间方差阈值分割法日本大津展之在1980年提出的,其基本思路是将图像的直方图以某一灰度为阈值,将图像分成两组并计算两组的方差,当被分成的两组之间的方差最大时,就以这个灰度值为國值分割图像 ...

  4. SAR成像系列:【3】合成孔径雷达(SAR)的二维回波信号与简单距离多普勒(RD)算法 (附matlab代码)

    合成孔径雷达发射信号以线性调频信号(LFM)为基础,目前大部分合成孔径雷达都是LFM体制,为了减轻雷达重量也采用线性调频连续波(FMCW)体制:为了获得大带宽亦采用线性调频步进频(FMSF)体制. ( ...

  5. 【Halcon二维测量】——2D计量模型

    2D计量 2D 计量的概念 通过二维计量,可以测量用特定几何体表示的物体的尺寸.可以测量的几何形状包括圆圈.椭圆.矩形和线条.我们需要测量对象的位置.方向和尺寸的近似值.然后,图像中对象的实际边缘位置 ...

  6. Halcon_二维测量_Apply_bead_inspection_model

    这个例子展示了如何使用胎圈检查算子来检验粘合剂. 胎圈检查可用于检测以下错误: 1.缺少粘合胶的部分,断胶 2.粘合剂过多或过少的部分 3.粘合胶离其预定位置太远的部分 apply_bead_insp ...

  7. 【Halcon二维测量】——使用计量模型以亚像素精度测量圆和矩形

    算法大致思路如下:       1.创建计量模型模板并设置计量对象图像大小       2.根据先验知识生成相关图形形状,如矩形,圆,并将其加入到创建的模板中       3.设置模板的相关参数,包括 ...

  8. 二维测量--轮辋和轮胎的检查

    对应示例程序: rim.hdev 目标:提取圆孔以及包含印记字符的区域 思路为:       1.读取图像,窗口初始化       2.先定位圆孔的位置和测量直径:          a.分割提取出灰 ...

  9. 基于halcon的二维椭圆测量实例

    halcon二维测量 原图 代码 结果 原图 代码 dev_close_window () read_image (Src, 'src.bmp') get_image_size (Src, Width ...

最新文章

  1. 假装不知道有尽头(博弈论的诡计)
  2. 批量修改文件名称(Python)
  3. ABAP CCDEF, CCIMP, CCMAC, CCAU, CMXXX这些东东是什么鬼
  4. java 6 jaxb_JAVA6开发WebService (五)—— JAXB
  5. 深入理解BS结构应用程序
  6. 为什么用c语言程序中的if语句实现从1加到100最后的结果是负数,用C语言程式计算从1加到100的程式是怎样的?...
  7. RFID芯片有什么用
  8. 20191016:(leetcode习题)寻找两个有序数组的中位数
  9. 【解决】小程序要求的 TLS 版本必须大于等于 1.2
  10. 保存单文件为mhtml
  11. paip.oracle10g dmp文件导入总结
  12. 国家计算机考试报名照片编辑器,电脑的证件照制作软件推荐
  13. 为什么一打电话就显示服务器故障,手机打电话黑屏怎么回事?手机打电话时出现黑屏情况的解决办法介绍...
  14. 纳什均衡C++简单实现
  15. Julia 安装包报错操作超时
  16. 海思SD3403开发板学习(二)
  17. 瞬时频率函数matlab,瞬时频率估计的相位建模法及Matlab的实现
  18. YouTube儿童版的四种选择(其中不包含令人毛骨悚然的假视频)
  19. java编写图书管理系统
  20. 【报错解决01】分层抽样报错ValueError: The least populated class in y has only 1 member

热门文章

  1. IT技术人员的自我修养
  2. 微信小程序全局变量(globalData)和缓存(StorageSync)的区别和具体用法
  3. Linux文件系统类型介绍
  4. datax-web Windows10以开发者模式部署
  5. qq在线状态客户代码与图标
  6. JavaScript 数值转换为字符串
  7. 与计算机学男生谈恋爱,和不同专业的男生谈恋爱是什么感觉?
  8. Linux课堂篇3_Linux目录结构、快捷键、常用基础命令
  9. Ubuntu18.04 小米游戏本最早一代 双硬盘 安装 过程记录
  10. iframe如何发送请求_【第1803期】如何在 Web 上构建一个插件系统