在我的上一篇文章中介绍了AOI中通用的图像检测方法——母版比对。现在如下的代码实现了如何进行母版比对。其中提升检测率的方法有3个:
(1)将RGB图转换为灰度图再进行比对
(2)将母版图上的金面作为ROI
(3)使用腐蚀算子来消除边缘干扰

****************************************************************
*使用与母版相减的方式
***************************************************************
(1)将RGB图转换为灰度图再进行比对
***************************************************************
rgb1_to_gray (BrightLeftWireBondingImageReduced, GrayRec)
rgb1_to_gray(DarkLeftWireBondingImageReduced,GrayStandard)
****************************************************************
(2)根据母版图像的金面设定检测区域
****************************************************************
threshold (GrayStandardImageReduced, StandardRegion, 200, 255)
****************************************************************
(3)使用腐蚀算子来消除边缘干扰
****************************************************************
erosion_circle (StandardRegion, StandardRegion, 2)
*缩小检测范围
reduce_domain (GrayRec, StandardRegion, GrayRecImageReduced)
reduce_domain (GrayStandard, StandardRegion, GrayStandardImageReduced)
abs_diff_image (GrayRecImageReduced,GrayStandardImageReduced,ImageAbsDiff, 1)
threshold (ImageAbsDiff, Region, 80, 255)
connection (Region, ConnectedRegions)
*误差主要是水平线,因此通过高度大于3个像素、面积大于9个像素来判断
select_shape (ConnectedRegions, ConnectedRegions, [‘area’,’height’], ‘and’, [9,3], [99999,99999])
count_obj (ConnectedRegions, Number)
if(Number > 0)
CurrentNgLight := 0
CurrentNgCode := 0
union1 (ConnectedRegions, RegionUnion)
smallest_rectangle1 (RegionUnion, Row1, Column1, Row2, Column2)
CurrentNgPos := [Row1-10, Column1-10, Row2+10, Column2+10]
CurrentNgDescribe := ‘LWBConnectedRegions有变色’
MFOL2_Gather_Ng (CurrentNgCode, CurrentNgPos, CurrentNgDescribe, 0, 0)
endif
return ()