换向器如图所示
针对图示的八种换向器表面缺陷,依托德国MVtec公司的Halcon软件平台来设计实施有效的缺陷检测算法与程序。
八种缺陷说明
槽边毛刺:在槽的加工过程产生的紧靠槽边的毛刺,如图(所示。
槽边毛刺
槽打伤,尾端槽口打伤,外圆打伤:相应部位因撞击产生的凹坑,分别如图所示。
(b)槽打伤
(g)尾端槽口打伤
(h)尾端槽口毛刺
槽内卡铜丝:切削换向片表面产生的铜丝进入槽内部,如图所示。
槽内毛刺:在槽的加工过程产生的位于槽内部的毛刺,如图所示。
外圆不圆:换向器侧表面部分区域曲率半径与整体相差过大而未能接触到刀具,表现为切削前的状态,颜色泛绿是由于铜锈的缘故所示。
外圆打伤:在右侧端面加工过程中产生的毛刺, 如图所示。
检测方案
线圈缺陷检测的目的是基于Halcon检测分析线圈的槽边毛刺、槽打伤、槽内卡铜丝、槽内毛刺、外圆不圆、外圆打伤、尾端槽口打伤、尾端槽口毛刺8种常见缺陷。首先分析各种缺陷的特征,然后根据缺陷特征类型确定各种缺陷的检测方法,最终采用不同的阈值分割、颜色检测等常用图像检测方法检测出线圈的缺陷类型以及位置。
1. 缺陷特征分析
1.1槽边毛刺
槽边毛刺缺陷特征在图像上表现为:开槽口小面积的灰度值变化,开槽形状凸起。
1.2槽打伤
槽打伤缺陷特征在图像上表现为:开槽的形状发生严重畸变。
1.3槽内卡铜丝
槽内卡铜丝缺陷特征在图像上表现为:槽内有大块异物。
1.4槽内毛刺
槽内毛刺缺陷特征在图像上表现为:开槽矩形小面积凹陷。
1.5外圆不圆
槽内毛刺缺陷特征在图像上表现为:由于光线反射导致线圈圆柱身部分颜色发生突变。
1.6外圆打伤
外圆打伤缺陷特征在图像上表现为:圆柱身部分灰度值变暗。
1.7尾端槽口打伤
尾端槽口打伤缺陷特征在图像上表现为:开槽尾端的形状发生严重畸变。
1.8槽边毛刺
槽边毛刺缺陷特征在图像上表现为:槽边的形状发生严重畸变。
2. 缺陷特征分类以及检测方案
根据线圈八种缺陷的特征进行分类,以此为基础确定检测方案。
2.1槽边毛刺、槽打伤、槽内毛刺、尾端槽口
槽边毛刺、槽打伤、槽内毛刺、尾端槽口打伤4中缺陷均为开槽形状发生变化的开槽口缺陷,因此这4种缺陷可通过检测线圈开槽的形状进行检测,其中槽边毛刺和槽内毛刺开槽形状均发生小面积突变,对于开槽形状而言槽边毛刺为凸起区域、槽内为凹陷区域。槽打伤和尾端槽口打伤开槽形状发生大面积畸变,其中尾端槽口打伤发生在开槽尾端区域。
2.2槽内卡铜丝
定位开槽区域后对开槽内的灰度值进行检测,如果存在大面积灰度值变化区域则认为开口槽内存在异物。
2.3外圆打伤
对线圈圆柱部分的灰度值进行检测分析,根据圆度部分灰度变化梯度可检测圆柱部分缺陷。
2.4外圆不圆
由于线圈外圆形状发生突变的时候外圆颜色发生了变化,为了排除反光效果的干扰,需要将图像有RGB(红、绿、蓝)空间转化至HSV(色调、饱和度、亮度)空间对其色调进行分析检测,从而检测出圆柱变化区域来判断是否有外圆不圆的缺陷。
2.5槽边毛刺
将图像转化至灰度图,定位槽边并分析其形状,根据形状突变情况确定槽边是否存在缺陷。
最终总的检测流程如下:
检测源码如图所示:
read_image (Image01, 'G:/机器视觉/20180118毕业设计/尾端槽口毛刺02.bmp')
**1.将读入图像分别转化为灰度图以供后续检测,将图像由RGB空间转化到HSV空间以便根据颜色检测外圆不圆
rgb1_to_gray (Image01, GrayImage)
decompose3 (Image01, ImageR, ImageG, ImageB)
trans_from_rgb (ImageR, ImageG, ImageB, ImageH, ImageS, ImageV, 'hsv')
**2.定位开槽、外圆部分、尾边等ROI区域
***1).定位开槽区域
threshold (GrayImage, Region, 50, 255)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 100000, 9999999)
union1 (SelectedRegions, RegionUnion)
closing_rectangle1 (RegionUnion, RegionClosing, 2, 100)
difference (RegionClosing, RegionUnion, RegionDifference)
connection (RegionDifference, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 3999, 99999)
union1 (SelectedRegions1, RegionUnion1)
***2).初步检测槽内毛刺(开槽内陷)
opening_circle (RegionUnion1, RegionOpening2, 3.5)
closing_rectangle1 (RegionOpening2, RegionClosing5, 20, 2)
difference (RegionClosing5, RegionOpening2, RegionDifference8)
connection (RegionDifference8, ConnectedRegions8)
select_shape (ConnectedRegions8, CaoneiMaoci, 'area', 'and', 50, 99999)
***3).初步检测铜带(开槽中间有异物)
opening_rectangle1 (RegionOpening2, RegionOpening5, 100, 2)
closing_rectangle1 (RegionOpening5, RegionClosing4, 150, 2)
difference (RegionClosing4, RegionOpening5, RegionDifference7)
connection (RegionDifference7, ConnectedRegions7)
select_shape (ConnectedRegions7, Tongdai, 'area', 'and', 1000, 99999)
dilation_circle (Tongdai, Tongdai, 5)
***4).根据开槽区域定位整体需要检测的区域
area_center (RegionOpening5, Area, Row, Column)
gen_rectangle1 (Rectangle, 0, 0, Row-250, 1280)
gen_rectangle1 (Rectangle1, Row+250, 0, 960, 1280)
union2 (Rectangle, Rectangle1, RegionUnion2)
threshold (GrayImage, Region2, 0, 40)
difference (Region2, RegionUnion2, RegionDifference2)
fill_up (RegionDifference2, RegionFillUp)
closing_circle (RegionFillUp, RegionClosing2, 3.5)
opening_circle (RegionClosing2, RegionOpening3, 30)
connection (RegionOpening3, ConnectedRegions2)
select_shape_std (ConnectedRegions2, SelectedRegions2, 'max_area', 70)
dilation_circle (SelectedRegions2, RegionDilation, 60)
smallest_rectangle1 (RegionDilation, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle2, Row1-100, Column1, Row2+100, Column2)
difference (RegionUnion2, Rectangle2, RegionDifference3)
union2 (RegionUnion2, Rectangle2, RegionUnion3)
complement (RegionUnion3, RegionComplement)
***5).定位尾边检测区域,检测槽口毛刺
reduce_domain (GrayImage, RegionComplement, ImageReduced)
threshold (ImageReduced, Region3, 250, 255)
connection (Region3, ConnectedRegions3)
select_shape (ConnectedRegions3, SelectedRegions3, 'area', 'and', 1500, 99999)
select_shape (SelectedRegions3, SelectedRegions4, 'height', 'and', 200, 99999)
union1 (SelectedRegions4, RegionUnion4)
fill_up (RegionUnion4, RegionFillUp1)
closing_rectangle1 (RegionFillUp1, RegionClosing3, 10, 50)
opening_rectangle1 (RegionClosing3, RegionOpening7, 2, 20)
difference (RegionClosing3, RegionOpening7, RegionDifference11)
connection (RegionDifference11, ConnectedRegions11)
select_shape (ConnectedRegions11, CaokouMaoci, 'area', 'and', 50, 99999)
***6).初步检测槽边毛刺
difference (RegionOpening2, RegionClosing3, RegionDifference4)
difference (RegionDifference4, RegionUnion3, RegionDifference5)
connection (RegionDifference5, ConnectedRegions4)
select_shape (ConnectedRegions4, SelectedRegions5, 'area', 'and', 3999, 99999)
dilation_circle (SelectedRegions5, RegionDilation1, 20)
intersection (RegionDilation1, RegionComplement, RegionIntersection)
reduce_domain (GrayImage, RegionIntersection, ImageReduced1)
threshold (ImageReduced1, Region4, 0, 60)
connection (Region4, ConnectedRegions5)
select_shape (ConnectedRegions5, SelectedRegions6, 'area', 'and', 4000, 99999)
opening_rectangle1 (SelectedRegions6, RegionOpening4, 150, 2)
difference (SelectedRegions6, RegionOpening4, RegionDifference6)
opening_circle (RegionDifference6, RegionOpening6, 1.5)
connection (RegionOpening6, ConnectedRegions6)
select_shape (ConnectedRegions6, CaobianMaoci1, 'area', 'and', 50, 99999)
select_shape (CaobianMaoci1, CaobianMaoci, 'width', 'and', 0, 20)
select_shape (CaobianMaoci, CaobianMaoci, 'height', 'and', 10, 999999)
union1 (CaobianMaoci1, RegionUnion6)
closing_rectangle1 (RegionUnion6, RegionClosing6, 2, 150)
connection (RegionClosing6, ConnectedRegions12)
select_shape (ConnectedRegions12, Caokoudashang, 'height', 'and', 45, 99999)
union1 (Caokoudashang, Caokoudashang)
dilation_circle (Caokoudashang, RegionDilation3, 100)
difference (CaobianMaoci, RegionDilation3, CaobianMaoci)
***7).根据颜色检测外圆不圆
mean_image (ImageH, ImageMean, 12, 12)
median_image (ImageH, ImageMedian, 'circle', 5, 'mirrored')
threshold (ImageMedian, Region1, 45, 255)
closing_rectangle1 (Region1, RegionClosing1, 10, 200)
opening_rectangle1 (RegionClosing1, RegionOpening, 10, 800)
difference (RegionClosing1, RegionOpening, RegionDifference1)
opening_circle (RegionDifference1, WaiYuanBuyuan, 30)
***8).动态阈值分割检测外圆打伤
dilation_circle (RegionClosing3, RegionDilation2, 10)
difference (RegionComplement, RegionDilation2, RegionDifference9)
connection (RegionDifference9, ConnectedRegions9)
select_shape_std (ConnectedRegions9, SelectedRegions8, 'max_area', 70)
difference (SelectedRegions8, RegionDilation1, RegionDifference10)
reduce_domain (GrayImage, RegionDifference10, ImageReduced2)
mean_image (ImageReduced2, ImageMean1, 30, 30)
dyn_threshold (ImageReduced2, ImageMean1, RegionDynThresh, 40, 'dark')
opening_circle (RegionDynThresh, RegionOpening1, 1.5)
connection (RegionOpening1, ConnectedRegions10)
select_shape (ConnectedRegions10, WaiYuanDaShang, 'area', 'and', 200, 99999)
**3.根据各缺陷位置关系进一步精确检验
***铜带区域不会有槽口毛刺
difference (CaokouMaoci, Tongdai, CaokouMaoci)
***尾边区域不会有槽内毛刺
difference (CaoneiMaoci, RegionDilation2, CaoneiMaoci)
difference (CaoneiMaoci, Tongdai, CaoneiMaoci)
***槽内毛刺一定在开槽区域
intersection (CaoneiMaoci, RegionDilation1, CaoneiMaoci)
difference (Caokoudashang, Tongdai, Caokoudashang)
intersection (Caokoudashang, RegionDilation1, Caokoudashang)
***外圆不圆一定在检测区域
intersection (WaiYuanBuyuan, RegionComplement, WaiYuanBuyuan)
difference (CaobianMaoci, Tongdai, CaobianMaoci)
intersection (CaobianMaoci, SelectedRegions8, CaobianMaoci)
**4.对检测结果进行显示
area_center (CaobianMaoci, Area1, Row3, Column3)
dev_display (Image01)
dev_set_draw ('fill')
try
if(Area1[0]>10)
dev_set_color ('red')
dev_display (CaobianMaoci)
disp_message (3600, 'CaoBianMaoci', 'window', 12, 12, 'red', 'false')
endif
catch (Exception)
endtry
area_center (CaokouMaoci, Area2, Row4, Column4)
try
if(Area2[0]>10)
dev_set_color ('blue')
dev_display (CaokouMaoci)
disp_message (3600, 'CaoKouMaoCi', 'window', 27, 12, 'blue', 'false')
endif
catch (Exception)
endtry
area_center (CaoneiMaoci, Area3, Row5, Column5)
try
if(Area3[0]>10)
dev_set_color ('green')
dev_display (CaoneiMaoci)
disp_message (3600, 'CaoNeiMaoCi', 'window', 87, 12, 'green', 'false')
endif
catch (Exception)
endtry
area_center (Caokoudashang, Area4, Row6, Column6)
try
)
if(Column6[0]<990)
dev_set_color ('cyan')
dev_display (Caokoudashang)
disp_message (3600, 'CaoKouDaShang', 'window', 72, 12, 'cyan', 'false')
else
dev_set_color ('slate blue')
dev_display (Caokoudashang)
disp_message (3600, 'WeiDuanCaoKouDaShang', 'window', 72, 12, 'slate blue', 'false')
endif
endif
catch (Exception)
endtry
dev_set_draw ('margin')
area_center (WaiYuanBuyuan, Area5, Row7, Column7)
try
if(Area5[0]>10)
dev_set_color ('magenta')
dev_display (WaiYuanBuyuan)
disp_message (3600, 'WaiYuanBuyuan', 'window', 42, 12, 'magenta', 'false')
endif
catch (Exception)
endtry
area_center (Tongdai, Area6, Row8, Column8)
try
if(Area6[0]>10)
dev_set_color ('spring green')
dev_display (Tongdai)
disp_message (3600, 'TongDai', 'window', 57, 12, 'spring green', 'false')
endif
catch (Exception)
endtry
area_center (WaiYuanDaShang, Area7, Row9, Column9)
try
if(Area7[0]>10)
dev_set_color ('coral')
dev_display (WaiYuanDaShang)
disp_message (3600, 'WaiYuanDaShang', 'window', 102, 12, 'coral', 'false')
endif
catch (Exception)
endtry
检测效果如图所示:
更多缺陷检测算法参照本公众号以下相关文章: