思路:
提取OK焊点,建立模板。
将模板映射到每次来料焊点,计算相邻两焊点之间的距离。
通过距离、各项异性(‘anisometry)、灰度值,筛选出NG的焊点区域。
提取焊点region:
fast_threshold (Image, Region, 95, 255, 3)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ['area','anisometry'], 'and', [20,1.0], [100,1.7])
dilation_rectangle1 (SelectedRegions, RegionDilation, 3, 3)
计算每个焊点特征(灰度值、长宽比):
area_center_gray (RegionDilation, Image, VolumeCheck, RowCheck, ColumnCheck)
elliptic_axis_gray (RegionDilation, Image, RaCheck, RbCheck, PhiCheck)
AnisometryCheck := RaCheck / RbCheck
刚性变换消除角度,建立模板:
gen_region_points (RegionBGACenters, RowCheck, ColumnCheck)
smallest_rectangle2 (RegionBGACenters, RowBGACheck, ColumnBGACheck, PhiBGACheck, Length1BGACheck, Length2BGACheck)
if (VisualizeIntermediate)
dev_display (Image)
dev_set_color ('red')
dev_display (RegionBGACenters)
dev_set_color ('green')
dev_set_draw ('margin')
gen_rectangle2 (BGARect, RowBGACheck, ColumnBGACheck, PhiBGACheck, Length1BGACheck, Length2BGACheck)
dev_display (BGARect)
dev_set_draw ('fill')
endif
*
* 2D transformation and normalization of the center points
*
BallDistCol := 2 * Length1BGACheck / (BallsPerCol - 1)
BallDistRow := 2 * Length2BGACheck / (BallsPerRow - 1)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_rotate (HomMat2DIdentity, -PhiBGACheck, RowBGACheck, ColumnBGACheck, HomMat2DRotate)
hom_mat2d_translate (HomMat2DRotate, -RowBGACheck + Length2BGACheck, -ColumnBGACheck + Length1BGACheck, HomMat2DTranslate)
hom_mat2d_scale (HomMat2DTranslate, 1 / BallDistRow, 1 / BallDistCol, 0, 0, HomMat2DScale)
affine_trans_point_2d (HomMat2DScale, RowCheck, ColumnCheck, RowNormalized, ColNormalized)
BGARowIndex := round(RowNormalized)
BGAColIndex := round(ColNormalized)
NumBalls := |RowCheck|
构建来料焊点与模板点位的刚性变换矩阵:
vector_to_rigid (Rows1, Cols1, Rows2, Cols2, HomMat2D)
将模板点位映射到来料上:
affine_trans_point_2d (HomMat2D, Rows1, Cols1, RowTrans, ColumnTrans)
筛选出NG区域:
for i := 0 to BallsPerRow * BallsPerCol - 1 by 1
if (BallMatrix[i] >= 0 and BallMatrixCheck[i] >= 0)
gen_ellipse (Ellipse, Rows2[j], Cols2[j], Phi2[j], Ra2[j], Rb2[j])
if (Distance[j] > 0.05)
concat_obj (EllipseDeviation, Ellipse, EllipseDeviation)
else
if (Anisometry2[j] > 1.2)
concat_obj (EllipseDeformation, Ellipse, EllipseDeformation)
else
if (Volume2[j] < 5500 or Volume2[j] > 10000)
concat_obj (EllipseVolume, Ellipse, EllipseVolume)
else
concat_obj (EllipseCorrect, Ellipse, EllipseCorrect)
endif
endif
endif
j := j + 1
else
if (BallMatrix[i] >= 0)
gen_cross_contour_xld (Cross, RowTransFull[BallMatrix[i]], ColumnTransFull[BallMatrix[i]], 10, 0.785398)
concat_obj (Missing, Cross, Missing)
endif
endif
endfor