halcon历程注解 circles.hdev 和clip_region_rel和get_contour_global_attrib_xld

* 图像中的边缘被分割成线和圆。
* 对于属于圆的边,估计圆的参数并显示得到的圆。

* 
* 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
* 分割包含边缘的区域
* 在支持SSE2指令集的多核计算机上,threshold很可能比fast_threshold快。
* Fast_threshold可能只在那些特性不可用的情况下被优先使用,例如在嵌入式平台上。
fast_threshold (Image, Region, 0, 120, 7)
boundary (Region, RegionBorder, 'inner')
* 在现有区域基础上,减去一个现有区域的最小外接矩形的每一条边
* 这样就可以去掉外围水平或垂直的区域,只留下弯曲的部分
clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5)
*
* 这个操作相当于:
* shape_trans (Region, RegionTrans, 'rectangle1')
* erosion_rectangle1 (RegionTrans, RegionErosion, 5, 5)
* intersection (RegionErosion, RegionBorder, RegionClipped)
*
dilation_circle (RegionClipped, RegionDilation, 2.5)
reduce_domain (Image, RegionDilation, ImageReduced)
* 
* In the subdomain of the image containing the edges,extract subpixel precise edges.
* 在包含边缘的图像的子域中,提取亚像素级的精确边缘。
* 使用Deriche, Lanser, Shen或Canny滤波器提取亚像素精确边缘
* Canny算子:使用累计直方图计算两个阀值。凡是大于高阀值的一定是边缘; 凡是小于低阀值的一定不是边缘;如果检测结果大于低阀值但又小于高阀值,那就要看这个像素的邻接像素中有没有超过高阀值的边缘像素:如果有的话那么它就是边缘了,否则他就不是边缘;
edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)
* 分割XLD轮廓线,可以选择'lines'(使用直线段分割), 'lines_circles'(使用直线段和圆(弧)分割), 'lines_ellipses'(使用直线段和椭圆弧分割)。
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)
    * 返回XLD轮廓的全局属性值
    * 分割得到的轮廓是直线段、圆(圆弧)或者椭圆弧可以通过分割后轮廓的全局属性'cont_approx’参数的值来确定(参考get_contour_global_attrib_xld)。
    * 如果'cont_approx'=-1,这一部分轮廓最适合被拟合为直线段。
    * 如果'cont_approx'=0,这一部分轮廓最适合被拟合为椭圆弧。
    * 如果'cont_approx'=1,这一部分轮廓最适合被拟合为圆弧。
    get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
    * Fit a circle to the line segment that are arcs of a circle
    * 将圆与圆弧的线段拟合
    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)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小菠萝0908

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值