Halcon表面缺陷检测-划痕检测
2019-07-16 22:37
1561 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xd940940/article/details/96196089
对应示例程序:
surface_scratch.hdev
目标:通过图像预处理和形态学处理提取划痕
思路为:
1.读取图像
2.自动阈值分割
3.连通域分割,提取出面积最大的区域
4.形态学处理,得到干净的目标图像
5.进行显示
图像:
代码:
dev_update_off () dev_close_window () * * Step 1: Acquire image 读取图像 * read_image (Image, 'surface_scratch') get_image_size (Image, Width, Height) dev_open_window_fit_image (Image, 0, 0, Width, Width, WindowID) set_display_font (WindowID, 16, 'mono', 'true', 'false') dev_set_draw ('margin') dev_set_line_width (4) dev_display (Image) Message := 'This program shows the extraction of' Message[1] := 'surface scratches via local thresholding' Message[2] := 'and morphological post-processing' disp_message (WindowID, Message, 'window', 12, 12, 'black', 'true') disp_continue_message (WindowID, 'black', 'true') stop () * * Step 2: Segment image 图像分割 * * Using a local threshold mean_image (Image, ImageMean, 7, 7) dyn_threshold (Image, ImageMean, DarkPixels, 5, 'dark') * * Extract connected components connection (DarkPixels, ConnectedRegions) dev_set_colored (12) dev_display (Image) dev_display (ConnectedRegions) Message := 'Connected components after image segmentation' Message[1] := 'using a local threshold.' disp_message (WindowID, Message, 'window', 12, 12, 'black', 'true') disp_continue_message (WindowID, 'black', 'true') stop () * * Step 3: Process regions 提取区域 * * Select large regions select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10, 1000) dev_display (Image) dev_display (SelectedRegions) disp_message (WindowID, 'Large Regions', 'window', 12, 12, 'black', 'true') disp_continue_message (WindowID, 'black', 'true') stop () * * Visualize fractioned scratch 划痕可视化 重新开了一个窗口 open_zoom_window (0, round(Width / 2), 2, 303, 137, 496, 3, WindowHandleZoom) dev_set_color ('blue') dev_display (Image) dev_display (SelectedRegions) set_display_font (WindowHandleZoom, 16, 'mono', 'true', 'false') disp_message (WindowHandleZoom, 'Fractioned scratches', 'window', 12, 12, 'black', 'true') disp_continue_message (WindowHandleZoom, 'black', 'true') stop () * * Merge fractioned scratches via morphology 通过形态学合并破碎的划痕 union1 (SelectedRegions, RegionUnion) dilation_circle (RegionUnion, RegionDilation, 3.5) dev_display (Image) dev_display (RegionDilation) Message := 'Region of the scratches after dilation' disp_message (WindowHandleZoom, Message, 'window', 12, 12, 'black', 'true') disp_continue_message (WindowHandleZoom, 'black', 'true') stop () skeleton (RegionDilation, Skeleton) connection (Skeleton, Errors) dev_set_colored (12) dev_display (Image) dev_display (Errors) Message := 'Fractioned scratches merged via morphology' disp_message (WindowHandleZoom, Message, 'window', 12, 12, 'black', 'true') disp_continue_message (WindowHandleZoom, 'black', 'true') stop () * * Distinguish small and large scratches 区分大的 和小的 划痕 进行显示 close_zoom_window (WindowHandleZoom, Width, Height) select_shape (Errors, Scratches, 'area', 'and', 50, 10000) select_shape (Errors, Dots, 'area', 'and', 1, 50) dev_display (Image) dev_set_color ('red') dev_display (Scratches) dev_set_color ('blue') dev_display (Dots) Message := 'Extracted surface scratches' Message[1] := 'Not categorized as scratches' disp_message (WindowID, Message, 'window', 440, 310, ['red','blue'], 'true')
用到的几个算子:
dyn_threshold—使用局部阈值分割图像
dilation_circle–圆形膨胀
skeleton–计算区域的骨架
select_shape–借助形状特征选择区域
connection–根据连通域分割图像
相关文章推荐
- halcon应用范围-表面检测4一利用带通滤波器来检测缺陷
- Halcon实例教程之金属表面划痕及裂缝检测
- Halcon实例教程之金属表面划痕及裂缝检测
- halcon应用范围-表面检测1一塑料制品表面缺陷检测
- halcon应用范围-表面检测3一高纹理图像中的缺陷检测
- 深度学习应用系列——计算机视觉:表面缺陷检测(一)
- 图像分割——钢铁表面缺陷检测
- 短切毡表面缺陷检测中的机器视觉技术
- 表面缺陷检测的几种方法
- Halcon学习笔记之缺陷检测(布匹、皮革、塑料)
- halcon缺陷检测的相关知识
- 划痕检测 opencv/halcon
- 线缆表面缺陷检测
- Halcon学习笔记之缺陷检测(二)
- 钢板表面缺陷感兴趣区域检测算法
- 用独立成分分析滤波器进行表面缺陷检测
- VIDI深度学习软件在粗糙金属表面缺陷检测中的应用
- 基于OpenCv的金属表面划痕检测
- VIDI软件在粗糙金属表面缺陷检测中的应用
- Halcon 学习总结——基于动态阈值法、GMM(高斯混合模型)、SVM(支持向量机)的网状物缺陷检测