Halcon学习---精准找出被检测区域的矩形轮廓

find_pads.hdev

dev_update_pc ('off')
dev_update_window ('off')
dev_update_var ('off')
read_image (Image, 'die_pads')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width * 2, Height * 2, 'black', WindowHandle)
dev_set_part (0, 0, Height - 1, Width - 1)
* Find the pads in the image using blob analysis.
*快速阈值分割
fast_threshold (Image, Region, 180, 255, 20)
*分割连通域
connection (Region, ConnectedRegions)
*使用面积和长短轴比值筛选区域
select_shape (ConnectedRegions, SelectedRegions, ['area','anisometry'], 'and', [200,1], [1200,2])
* Construct a ROI for subpixel-accurate edge detection.
*内部孔洞填充
fill_up (SelectedRegions, RegionFillUp)
*用“convex”凸包性变换区域的形状
shape_trans (RegionFillUp, RegionTrans, 'convex')
*将区域缩小到这个边界
boundary (RegionTrans, RegionBorder, 'inner')
*利用圆形元素进行膨胀
dilation_circle (RegionBorder, RegionDilation, 2.5)
*连通各个区域
union1 (RegionDilation, RegionUnion)
* Perform the subpixel-accurate edge detection.
*分离区域,减小图片定义域
reduce_domain (Image, RegionUnion, ImageReduced)
*用来求取边界
edges_sub_pix (ImageReduced, Edges, 'sobel_fast', 0.5, 20, 40)
* Select the edge fragments that belong to the pads.
*使用长度特征筛选边界
select_shape_xld (Edges, SelectedContours, 'contlength', 'and', 10, 200)
* Merge adjacent edge fragments to obtain one contour per pad.
*计算端点靠近的轮廓的并集
union_adjacent_contours_xld (SelectedContours, UnionContours, 2, 1, 'attr_keep')
* Fit rectangles robustly to the pads' edges.
*利用可旋转的矩形拟合轮廓
fit_rectangle2_contour_xld (UnionContours, 'tukey', -1, 0, 0, 3, 2, Row, Column, Phi, Length1, Length2, PointOrder)
* Generate rectangles from the fitting result for visualization purposes.
*创建矩形轮廓
gen_rectangle2_contour_xld (Rectangle, Row, Column, Phi, Length1, Length2)
dev_display (Image)
dev_set_colored (12)
dev_display (Rectangle)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

枫呱呱

如果这篇博文对你有用,求打赏

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

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

打赏作者

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

抵扣说明:

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

余额充值