通过拟合来求缺陷,对应halcon例程:方法—》轮廓线处理—》fit_rectangle2_contour_xld.hdev。
原图如下,要求检测出图中有缺陷的物体:
read_image (Image, '1.png')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
*快速二值化,与二值化是一致的,只不过多加了个参数,最后一个参数
*是保留尺寸大于该值的二值化区域,否则还要调用一个select_shape
fast_threshold (Image, Regions, 128, 255,10)
*利用形态学提取边界
boundary (Regions, RegionBorder, 'inner')
dilation_rectangle1 (RegionBorder, RegionDilation, 7, 7)
reduce_domain (Image, RegionDilation, ImageReduced)
*提取亚像素轮廓(canny边缘检测),1.7为