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)

Halcon学习---精准找出被检测区域的矩形轮廓_第1张图片

你可能感兴趣的:(Halcon学习)