【issue-halcon例程学习】circles.hdev

例程功能

 检查所描绘工具的轮廓。将边界分割为线形和圆形,对于属于圆的边,将估计圆参数并显示生成。

代码如下

* 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')
clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5)
dilation_circle (RegionClipped, RegionDilation, 2.5)
reduce_domain (Image, RegionDilation, ImageReduced)
* 
* In the subdomain of the image containing the edges,
* extract subpixel precise edges.
edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)
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)
    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)

要点

  1. 亚像素边缘提取比较耗时,出于对代码执行速度的要求,先裁剪再提取边缘;
	fast_threshold (Image, Region, 0, 120, 7) // Image已读
	boundary (Region, RegionBorder, 'inner') 
	clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5) // 根据最小外接矩形裁剪区域
	dilation_circle (RegionClipped, RegionDilation, 2.5) //做膨胀操作获取边界周围更多区域,对只取boundary有弥补作用
	reduce_domain (Image, RegionDilation, ImageReduced)
  1. 像素提取后,按需打散很关键,有助于后续筛选;
	edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)
	segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 3)
  1. get_contour_global_attrib_xld
    返回轮廓全局属性值。使用了参数cont_approx,值为-1,轮廓与线段近似;值为0,轮廓与椭圆弧近似;值为1,轮廓与圆弧近似;
  2. .根据轮廓拟合圆(这边作为后处理手段,使检测的每个轮廓为圆的一部分)
	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)
  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值