*关闭程序计数器,图形变量更新,窗口图形更新
dev_update_window ('off')
*读取一张图像
read_image (Image, 'plastic_mesh/plastic_mesh_01')
*关闭打开的窗口
dev_close_window ()
*获取图像大小
get_image_size (Image, Width, Height)
*创建一个新窗口
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowHandle)
*设置字体信息:字体大小为16,字体为mono,粗体,斜体
set_display_font (WindowHandle, 18, 'mono', 'true', 'false')
*设置区域的填充方式
dev_set_draw ('margin')
*设置线宽度
dev_set_line_width (3)
for J := 1 to 14 by 1
*读取一张图像
read_image (Image, 'plastic_mesh/plastic_mesh_' + J$'02')
*均值滤波
mean_image (Image, ImageMean, 49, 49)
*局部阈值分割图像
dyn_threshold (Image, ImageMean, RegionDynThresh, 5, 'dark')
*对分割后的区域进行连通处理
connection (RegionDynThresh, ConnectedRegions)
*过滤出缺陷网孔区域
select_shape (ConnectedRegions, ErrorRegions, 'area', 'and', 500, 99999)
*统计出缺陷网孔的数目
count_obj (ErrorRegions, NumErrors)
*显示图像
dev_display (Image)
*设置对象的显示颜色
dev_set_color ('red')
*显示缺陷网孔
dev_display (ErrorRegions)
if (NumErrors > 0)
*显示产品NG
disp_message (WindowHandle, 'Mesh not OK', 'window', 24, 12, 'black', 'true')
else
*显示产品OK
disp_message (WindowHandle, 'Mesh OK', 'window', 24, 12, 'black', 'true')
endif
stop()
endfor
halcon 网状产品表面破损检测
于 2022-01-23 00:57:01 首次发布