halcon 边沿检测识别

* 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.
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)
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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值