1.blob分析+特征
基本定义:
read_image (Image, 'food/hazelnut_wafer_01')
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
*dev_update_window指定是否在活动图形窗口中显示由算子调用返回的所有图标对象(DisplayMode ='on' - 默认)或不显示(DisplayMode ='off')。(不支持代码导出)
dev_update_window ('off')
*dev_set_line_width定义用于显示region轮廓('margin'模式)
dev_set_line_width (3)
*dev_set_draw定义region的填充模式。 如果DrawMode设置为'fill',region显示为填 充,如果设置为'margin',则只显示轮廓。 在'margin'模式下,轮廓的外观会受到 dev_set_line_width,set_line_approx和set_line_style的影响。
dev_set_draw ('margin')
*设置字体
set_display_font (WindowHandle, 20, 'mono', 'true', 'false')
for Index := 1 to 24 by 1 *循环读图,每张图进行分析
read_image (Image, 'food/hazelnut_wafer_' + Index$'.02') *图像采集
binary_threshold (Image, Foreground, 'smooth_histo', 'light', UsedThreshold) *图像分割,使用直方图方法来寻找二值化阈值,直方图是图像的重要特质,直方图方法选择二值化阈值主要是发现图像的两个最高的峰,然后在阈值取值在两个峰之间的峰谷最低处。
opening_circle (Foreground, FinalRegion, 8.5) * 开运算=腐蚀+膨胀;(断开细小的地方,所以叫开) 将Foreground中去掉半径小于8.5的圆形区域后,将剩下的的区域保存到FinalRegion中
area_holes (FinalRegion, AreaHoles) *计算区域的孔面积(上一个算子中区域)。
rectangularity (FinalRegion, Rectangularity) *求取区域的矩形度。
dev_display (Image)
*如果孔洞过多面积超过300或者矩形度小于0.92,认为破损。矩形度体现物体对其外接矩形的充满程度,反映一个物体与矩形相似程度的一个参数
if (AreaHoles > 300 or Rectangularity < 0.92)
dev_set_color ('red')
Text := 'Not OK'
else
dev_set_color ('forest green')
Text := 'OK'
endif
dev_display (FinalRegion)
disp_message (WindowHandle, Text, 'window', -1, -1, '', 'false')
if (Index < 24)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
/*
binary_threshold(Image : Region : Method, LightDark : UsedThreshold)
参数:
Image:需要进行阈值的图像
Region:处理后的区域
Method:分割方法(‘max_separability’:最大限度的可分性, ‘smooth_histo’:直方图平滑)
LightDark:提取的是黑色部分还是白色部分
UsedThreshold:自动阈值使用的阈值值
*/
缺陷
1️⃣:凸凹缺陷;
2️⃣:污点内部凸凹点;
3️⃣:划痕
方法:
1️⃣打光:环形光低角度打光/同轴光打除反光/不同角度打光/调光对打;
2️⃣处理算法:
1.blob分析+特征;
2.blob分析+特征+差分;
3.频域+空间;
4.光度立体法;
5.特征训练;
6.测量+拟合。
图像处理的步骤:1.图像采集 2.预处理 3.图像分割 4.特征提取 5.通讯,显示…
ctrl+e 列子快捷方式