1、凹坑检测案例
* 使用元组的方法
ImageFile:=[]
ImageFile[0]:='D:/Halcon/产品上的凹坑检测/1.bmp'
ImageFile[1]:='D:/Halcon/产品上的凹坑检测/2.bmp'
for Index := 0 to |ImageFile|-1 by 1
read_image (Image, ImageFile[Index])
* 二值化
threshold (Image, Region, 100, 255)
* 连通性
connection (Region, ConnectedRegions)
* 筛选
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 40000, 99999)
* 裁剪
reduce_domain (Image, SelectedRegions, ImageReduced)
* 高斯卷积(平滑)
derivate_gauss (ImageReduced, DerivGauss, 1.5, 'gradient')
* 二值化
threshold (DerivGauss, Region1, 9, 50)
* 连通性
connection (Region1, ConnectedRegions1)
* 筛选最大的轮廓区域
select_shape_std (ConnectedRegions1, SelectedRegions1, 'max_area', 70)
* 填充区域
fill_up (SelectedRegions1, RegionFillUp)
* 计算轮廓区与填充区的补集
difference (RegionFillUp, SelectedRegions1, RegionDifference)
* 连通性
connection (RegionDifference, ConnectedRegions2)
* 筛选
select_shape (ConnectedRegions2, SelectedRegions2, 'area', 'and', 100, 500)
* 区域轮廓线
gen_contour_region_xld (SelectedRegions2, Contours, 'border')
dev_display (Image)
dev_display (Contours)
stop()
endfor
2、求网格的交点案例
read_image (Image, 'D:/Halcon/求网格的顶点.png')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
* 均值滤波
mean_image (Image, ImageMean, 10, 10)
* 动态阈值处理
dyn_threshold (Image, ImageMean, RegionDynThresh, 5, 'dark')
* 连通性
connection (RegionDynThresh, ConnectedRegions)
* 筛选最大的轮廓区域
select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 70)
* 开运算,获取网格的竖线
opening_rectangle1 (SelectedRegions, RegionOpening, 1, 10)
* 开运算,获取网格的横线
opening_rectangle1 (SelectedRegions, RegionOpening1, 10, 1)
* 交集(两个ROI相交的部分)
intersection (RegionOpening, RegionOpening1, RegionIntersection)
connection (RegionIntersection, ConnectedRegions1)
area_center (ConnectedRegions1, Area, Row, Column)
dev_display (Image)
dev_display (ConnectedRegions1)