* 使用元组的方法
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