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

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

跟我学机器视觉-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.

相关文档
最新文档