Halcon例程分析3:焊盘定位

打开halcon,按下ctrl+e打开halcon自带例程。工业领域->半导体业->find_pads.hdev

通过blob分析,应用矩形拟合方式定位焊盘点位置。

* This example program shows how to find pads in an image and how to
* determine their position, rotation, and size robustly and accurately using
* fit_rectangle2_contour_xld.
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.
*快速阈值话,寻找图像中灰度值180-255的区域,最后一个参数是寻找区域的最小尺寸,小于这个尺寸的区域被舍弃
fast_threshold (Image, Region, 180, 255, 20)
*分离区域,不要被这个函数的名字骗了
connection (Region, ConnectedRegions)
*选择区域,通过面积和长宽比这两个特征筛选区域,在图像上右键-》工具-》特征检测
*在这里要点鼠标右键,显示选中ConnectedRegions这张图像,然后点选需要查看特征的区域,'anisometry'这个特征在shape一栏
select_shape (ConnectedRegions, SelectedRegions, ['area','anisometry'], 'and', [200,1], [1200,2])
* Construct a ROI for subpixel-accurate edge detection.
*填充区域
fill_up (SelectedRegions, RegionFillUp)
*形状转换,填充凹进去的区域
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.
*轮廓选择,跟区域的特征选择一样,这里用轮廓长度这个特征,在xld->shape->xld_contlength里面
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)

原始图像输入

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

究极调参工程师

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

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

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

打赏作者

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

抵扣说明:

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

余额充值