Halcon示例程序Circle 解析

匿名 (未验证) 提交于 2019-12-03 00:18:01

一、起语

昨天复习了一下关于Halcon中XLD相关的内容,今天看了看Halcon中相关的例子程序,下面对Circle这个例子做下解析

二、例子解析

*将图像中的边缘的分割成线段和圆弧线,根据圆弧线段的属性,选择边缘中的圆弧部分,
并完成最终圆的显示任务。 * The edges in the image are segmented into lines and circles. * For the edges that are part of a circle, the circle parameters * are estimated and the resulting circle is displayed.

*第一部分 读图显示

read_image (Image, 'double_circle') *  * Init window dev_close_window () get_image_size (Image, Width, Height) dev_open_window (0, 0, Width, Height, 'black', WindowHandle) * 

*第二部分 分割求边缘

* Segment a region containing the edges *快速阈值分割 fast_threshold (Image, Region, 0, 120, 7) *提取区域边界 boundary (Region, RegionBorder, 'inner') *在图像上下左右 4个方向各缩减5个像素(去除不需要部分) clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5) *对轮廓进行圆膨胀 dilation_circle (RegionClipped, RegionDilation, 2.5) *提取膨胀后轮廓在图像中对应区域(为后续提取图像XLD轮廓做准备) reduce_domain (Image, RegionDilation, ImageReduced) * In the subdomain of the image containing the edges, * extract subpixel precise edges. *提取XLD轮廓 edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60) *分割提取到的XLD轮廓 segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 3) *计算分割后轮廓的个数 count_obj (ContoursSplit, Number) dev_display (Image) dev_set_draw ('margin') dev_set_color ('white') dev_update_window ('off')

*第三部分 根据轮廓属性选取圆弧 并完成拟合

for I := 1 to Number by 1 *根据序号选择轮廓段     select_obj (ContoursSplit, ObjectSelected, I) *获取轮廓段的cont_approx属性值     get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)     * Fit a circle to the line segment that are arcs of a circle *筛选出属性值大于0 的轮廓段     if (Attrib > 0) *将筛选出的轮廓段拟合成圆 并完成显示         fit_circle_contour_xld (ObjectSelected, 'ahuber', -1, 2, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)         gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, rad(360), 'positive', 1.0)         dev_display (ContCircle)     endif endfor dev_set_colored (12) dev_set_line_width (3) dev_display (ContoursSplit)

三、总结

作用:获取制定轮廓段的制定属性状况

对于其 cont_approx属性 可判断轮廓段的种类是直线、圆弧 还是 椭圆弧 具体如下:




标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!