基于halcon的焊点识别-BLOB分析
在工作中会用到Halcon来解决项目问题,在这里通过案例分享,帮助大家少走弯路
blob分析一般流程:1)采集图像 2)预处理 3)分割 4)计算
废话不多说,开始代码:
dev_close_window () //关闭一个窗体
dev_open_window (0, 0, 512, 512, 'black', WindowHandle) //打开一个窗体
*1.采集图像
read_image (Die03, 'die_03.png')
*2.预处理
threshold (Die03, Regions, 95, 237) //二值化
shape_trans (Regions, RegionTrans, 'rectangle1') //区域形状变换(
reduce_domain (Die03, RegionTrans, ImageReduced) //对图像的尺寸进行剪裁
*3.分割
threshold (ImageReduced, Regions1, 0, 40) //二值化
opening_circle (Regions1, RegionOpening, 15) //15表示结构元素的半径 开运算
connection (RegionOpening, ConnectedRegions) //联通域断开
select_shape (ConnectedRegions, SelectedRegions, ['area','circularity'], 'and', [0,0.86272], [5000,1])//区域特征筛选
sort_region (SelectedRegions, SortedRegions, 'first_point', 'true', 'column')//区域排序
*计算
smallest_circle (SortedRegions, Row, Column, Radius) // 对区域求最小外接圆 半径 圆心
D:=Radius
dev_display (Die03) //显示图像
dev_display (SortedRegions) //显示区域
disp_message (WindowHandle, D, 'window', 0, 0, 'black', 'true') //显示文字



浙公网安备 33010602011771号