网格缺陷检测
图片资源
链接:https://pan.baidu.com/s/1Higp9T94J1KtlxCyYZrW1Q
提取码:z2wn
*************1、读取图片与基本设置**************
* 关闭图像更新
dev_update_window('off')
* 读取第一张
read_image (Image, './img/plastic_mesh_01.png')
* 关闭打开的窗口
dev_close_window ()
* 获取图片大小
get_image_size (Image, Width, Height)
* 打开适合的窗体
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowHandle)
* 设置显示的字体
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_display (Image)
dev_set_draw ('margin')
dev_set_line_width (3)
*************循环处理图片**************
for index := 1 to 14 by 1
***1、读取图片*********************************
ImagePath := './img/plastic_mesh_' + index $'02i' + '.png'
read_image (ImageOrg, ImagePath)
***2、动态阈值分析(有缺陷会连接在一起) **********
mean_image (ImageOrg, ImageMean, 49, 49)
dyn_threshold (ImageOrg, ImageMean, RegionDynThresh, 5, 'dark')
***3、连通域分析 面积筛选缺陷个数 ***************
connection (RegionDynThresh, ConnectedRegions)
* 面积筛选 单个面积在 300左右, 如果面积超过 500说明是缺陷
select_shape (ConnectedRegions, ErrorRegions, 'area', 'and', 500, 99999)
* 统计缺陷个数
count_obj (ErrorRegions, Number)
***4、显示结果 *********************************
dev_display (ImageOrg)
dev_set_color ('red')
dev_display (ErrorRegions)
if(Number > 0)
disp_message (WindowHandle, 'Mesh NG '+'Count:'+Number $'02i', 'window', 24, 12, 'black', 'true')
else
disp_message (WindowHandle, 'Mesh OK', 'window', 24, 12, 'black', 'true')
endif
stop()
endfor