跟我学机器视觉-HALCON学习例程中文详解-测量圆环脚宽间距

  • This example program demonstrates the basic usage of a circular measure object.

  • Here, the task is to determine the width of the cogs.

*首先读取图像,获取图像的宽度和高度

  • First, read in the image and initialize the program.

read_image (Image, 'rings_and_nuts')

dev_close_window ()

dev_open_window_fit_image (Image, 0, 0, 640, 640, WindowHandle)

set_display_font (WindowHandle, 14, 'mono', 'true', 'false')

get_image_size (Image, Width, Height)

*读到的图像如下:

  • Extract the rings.

自动阈值分割,此时为一个区域,如图*********

bin_threshold (Image, Region)

**********进行连通区域划分,不同的区域用不同的颜色表示,如图:

connection (Region, ConnectedRegions)

*填充区域内的孔洞,效果如图

fill_up (ConnectedRegions, RegionFillUp)

**计算区域的紧性,机器视觉算法与应用第168页

compactness (RegionFillUp, Compactness)

****通过紧性特征进行区域筛选,在1.5到2.5之间的为需要测量的圆环

for i := 0 to |Compactness|-1 by 1

if (Compactness[i] > 1.5 and Compactness[i] < 2.5)

    select_obj (RegionFillUp, ObjectSelected, i+1)

    * Determine the size and position of the rings.

计算选择区域的最小外接圆和最大内接圆,存储圆心和半径

两个半径的均值作为测量圆弧半径,AnnulusRadius 为测量圆弧宽度******************

    smallest_circle (ObjectSelected, Row, Column, RadiusMax)

    inner_circle (ObjectSelected, CenterRow, CenterCol, RadiusMin)

    Radius := (RadiusMax+RadiusMin)/2.0

    AnnulusRadius := (RadiusMax-RadiusMin)/4.0

    * Determine the position between two cogs.

    * This position is then used as the start angle for the circular ROI.

********多边形近似逼近区域,存储多边形角点的坐标值,机器视觉算法与应用第252页

    get_region_polygon (ObjectSelected, AnnulusRadius, RowsBorder, ColumnsBorder)

计算每个角点到最大内接圆圆心的距离,然后进行排序*************

SqrDistanceBorder := (RowsBorder-CenterRow)(RowsBorder-CenterRow) + (ColumnsBorder-CenterCol)(ColumnsBorder-CenterCol)

*************从小到大排序

tuple_sort_index (SqrDistanceBorder, Indices)

********计算直线的角度,圆心和到圆心最近的多边形角点所确定的直线

***************将该角度作为测量圆弧的起始角度

    line_orientation (CenterRow, CenterCol, RowsBorder[Indices[0]], ColumnsBorder[Indices[0]], AngleStart)

我认为检测圆开始角度直接设为0度也可以**************

  •   AngleStart := rad(0)
    
      AngleExtent := rad(360)
    
      * Create the measure for a circular ROI.
    
      Interpolation := 'bilinear'

生成测量圆弧,为完整圆环(360度)***

    gen_measure_arc (CenterRow, CenterCol, Radius, AngleStart, AngleExtent, AnnulusRadius, Width, Height, Interpolation, MeasureHandle)

    * Determine all edge pairs that have a negative transition, i.e., edge pairs

    * that enclose dark regions.

    * Note that the output parameters IntraDistance and InterDistance are given as arc lengths.

    Sigma := 1.0

    Threshold := 30

    Transition := 'negative'

    Select := 'all'

***进行边缘对测量,RowEdgeFirst, ColumnEdgeFirst,RowEdgeSecond, ColumnEdgeSecond为检测圆弧检测到的边界的中心点的坐标,

IntraDistance, InterDistance分别为边缘对间的距离和边缘对的弧线距离

    measure_pairs (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)

    * Determine the number of cogs.

    NumCogs := |RowEdgeFirst|

    * Determine the linear distance between the two edges of each edge pair ('Linear cog size')

    * as well as the angular distance of the edge pairs ('Angular cog size').

计算边缘对的直线距离和弧度*

    distance_pp (RowEdgeFirst, ColumnEdgeFirst, RowEdgeSecond, ColumnEdgeSecond, LinearDistance)

    AngularDistance := deg(IntraDistance/Radius)

 Visualize the determined edges.

将边缘对的起始终止点画出,并显示测量结果****

    gen_empty_obj (Crosses)

    for i := 0 to |RowEdgeFirst|-1 by 1

        gen_cross_contour_xld (Cross, RowEdgeFirst[i], ColumnEdgeFirst[i], AnnulusRadius*2.0, atan2(RowEdgeFirst[i]-CenterRow,ColumnEdgeFirst[i]-CenterCol))

        concat_obj (Crosses, Cross, Crosses)

        gen_cross_contour_xld (Cross, RowEdgeSecond[i], ColumnEdgeSecond[i], AnnulusRadius*2.0, atan2(RowEdgeSecond[i]-CenterRow,ColumnEdgeSecond[i]-CenterCol))

        concat_obj (Crosses, Cross, Crosses)

    endfor

    dev_display (Image)

    dev_set_line_width (4)

    dev_set_color ('black')

    dev_display (Crosses)

    dev_set_line_width (1)

    dev_set_color ('white')

    dev_display (Crosses)

    * Display the measured size of the cogs.

    disp_message (WindowHandle, 'Number of cogs: '+|RowEdgeFirst|+'                 ', 'window', 260, 10, 'black', 'true')

    disp_message (WindowHandle, 'Mean cog size:                    ', 'window', 286, 10, 'black', 'true')

    disp_message (WindowHandle, '- Arc length: '+mean(IntraDistance)$'.2f'+' +/- '+deviation(IntraDistance)$'.2f'+' pixel', 'window', 310, 10, 'black', 'true')

    disp_message (WindowHandle, '- Linear:     '+mean(LinearDistance)$'.2f'+' +/- '+deviation(LinearDistance)$'.2f'+' pixel', 'window', 334, 10, 'black', 'true')

    disp_message (WindowHandle, '- Angular:    '+mean(AngularDistance)$'.2f'+' +/- '+deviation(AngularDistance)$'.2f'+' deg  ', 'window', 358, 10, 'black', 'true')
*
* Close the measure close_measure (MeasureHandle) disp_continue_message (WindowHandle, 'black', 'true') stop () endif

for循环,测量其他圆环*****

endfor

跟我学机器视觉-HALCON学习例程中文详解-测量圆环脚宽间距的更多相关文章

  1. 跟我学机器视觉-HALCON学习例程中文详解-FUZZY检测用于开关引脚测量

    跟我学机器视觉-HALCON学习例程中文详解-FUZZY检测用于开关引脚测量 * This example program demonstrates the basic usage of a fuzz ...

  2. 跟我学机器视觉-HALCON学习例程中文详解-开关引脚测量

    跟我学机器视觉-HALCON学习例程中文详解-开关引脚测量 This example program demonstrates the basic usage of a measure object. ...

  3. 跟我学机器视觉-HALCON学习例程中文详解-QQ摄像头读取条码

    跟我学机器视觉-HALCON学习例程中文详解-QQ摄像头读取条码 第一步:插入QQ摄像头,安装好驱动(有的可能免驱动) 第二步:打开HDevelop,点击助手-打开新的Image Acquisitio ...

  4. 跟我学机器视觉-HALCON学习例程中文详解-IC引脚测量

    跟我学机器视觉-HALCON学习例程中文详解-IC引脚测量 Lead Measurement: Example for the application of the measure object in ...

  5. 《TensorFlow学习指南深度学习系统构建详解》英文PDF+源代码+部分中文PDF

    主要介绍如何使用 TensorFlow 框架进行深度学习系统的构建.涉及卷积神经网络.循环神经网络等核心的技术,并介绍了用于图像数据和文本序列数据的模型.给出了分布式深度学习系统在TensorFlow ...

  6. Nginx配置文件nginx.conf中文详解(转)

    ######Nginx配置文件nginx.conf中文详解##### #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_ ...

  7. Nginx中文详解、配置部署及高并发优化

      一.Nginx常用命令: 1. 启动 Nginx          /usr/local/nginx/sbin/nginxpoechant@ubuntu:sudo ./sbin/nginx2. 停 ...

  8. iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem

    http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...

  9. [转]iOS学习之UINavigationController详解与使用(三)ToolBar

    转载地址:http://blog.csdn.net/totogo2010/article/details/7682641 iOS学习之UINavigationController详解与使用(二)页面切 ...

随机推荐

  1. 【转】C#.net拖拽实现获得文件路径

    C#.net拖拽实现获得文件路径 作者Attilax ,  EMAIL:1466519819@qq.com 思路: 通过DragEnter事件获得被拖入窗口的“信息”(可以是若干文件,一些文字等等), ...

  2. WPF异步调用WCF服务

    wpf调用wcf时,第一次访问总耗时到达几秒,影响界面的用户体验,因此在wpf加载界面和加载数据时采用异步加载,即异步访问wcf服务, 由于是否采用异步加载和服务端无关,仅仅由客户端自己根据需要来选择 ...

  3. C# WinForm动态控件实例:口算训练

    昨天晚上回寝室看到室友正在被一个C#课的作业苦恼,作业的内容是编写一个口算训练程序,能够实现随意添加题目数量.于是,喜欢写C#的我就决定解救一下他们. 创建动态控件 既然要动态添加,那就必须使用动态控 ...

  4. python初准备:安装easy_install和pip

    安装easy_install wget http://peak.telecommunity.com/dist/ez_setup.py python ez_setup.py 安装pip wget htt ...

  5. 让WPF的Popup不总置顶的解决方案

    使用WPF的Popup的时候会发现有一个问题,它总是会置顶,只要Popup的StayOpen不设置为False,它就一直呆在最顶端,挡住其他的窗口. 解决方案是继承Popup重新定义控件PopupEx ...

  6. Centos 6.2上安装使用 Informix11.70 数据库

    环境要求:操作系统: Centos 6.2 32位数据库软件: iif.11.70.UC7IE.Linux-RHEL5.tar(在IBM网站上注册个帐号就可以下载,包括windows,Linux,Un ...

  7. 设置BootStrap导航条的高度

    只要加上这段css就可以覆盖Bootstrap.css的代码,定制符合自己的样式 .navbar { min-height: 40px; } .nav > li > a { padding ...

  8. 《JavaScript设计模式与开发实践》-面向对象的JavaScript

    设计模式 面向对象 动态类型语言 编程语言按照数据类型大体分为:静态类型语言和动态类型语言. 静态类型语言在编译时便已确定变量的类型,而动态类型语言的变量类型要到程序运行时,待变量被赋予某个值之后,才 ...

  9. 百度:在O(1)空间复杂度范围内对一个数组中前后连段有序数组进行归并排序

    一.题目理解 题目:数组al[0,mid-1]和al[mid,num-1]是各自有序的,对数组al[0,num-1]的两个子有序段进行merge,得到al[0,num-1]整体有序.要求空间复杂度为O ...

  10. 转:Linux Shell编程入门

    http://www.cnblogs.com/suyang/archive/2008/05/18/1201990.html 从程序员的角度来看, Shell本身是一种用C语言编写的程序,从用户的角度来 ...