下面两个是Halcon官方的示例,用来检测物体表面的划痕等

* This programm shows the extraction of surface scratches via
* local thresholding and morphological post-processing
* //此程序显示通过局部阈值和形态处理后提取表面划痕
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')

下面是类似的一个方法,

* This program shows how to detect defects (scratches) in
* an inhomogeneously illuminated surface by filtering in
* the frequency domain.
* First, a suitable bandpass filter is created. Then, the
* input image is fourier transformed and filtered in the
* frequency domain, so that high frequency information is
* enhanced. Finally, it is transformed back to the
* spatial domain and the enhanced defects are post-processed
* by morphology.
* 此程序显示如何检测缺陷(刮伤)中
* 通过在频率域中过滤,不生化地照亮表面。
* 首先,创建合适的带通滤镜。然后,
* 输入图像在频率域中经过四次转换和过滤,从而增强了高频信息。最后,它被转换回空间域,增强的缺陷通过形态处理后。
dev_update_off ()
dev_close_window ()
read_image (Image, 'surface_scratch')
invert_image (Image, ImageInverted)
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_display (Image)
*
* Optimize the speed of the fast fourier transform
* Message := 'Optimize the speed of the fast fourier transform.'
* Message[1] := 'Please wait...'
* disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
* optimize_rft_speed (Width, Height, 'standard')
* disp_continue_message (WindowHandle, 'black', 'true')
* stop ()
*
* Enhance the scratches by filtering in the frequency domain
gen_sin_bandpass (ImageBandpass, 0.4, 'none', 'rft', Width, Height)
rft_generic (ImageInverted, ImageFFT, 'to_freq', 'none', 'complex', Width)
convol_fft (ImageFFT, ImageBandpass, ImageConvol)
rft_generic (ImageConvol, Lines, 'from_freq', 'n', 'byte', Width)
*
* Segment the scratches by using morphology
threshold (Lines, Region, 5, 255)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 5, 5000)
dilation_circle (SelectedRegions, RegionDilation, 5.5)
union1 (RegionDilation, RegionUnion)
reduce_domain (Image, RegionUnion, ImageReduced)
lines_gauss (ImageReduced, LinesXLD, 0.8, 3, 5, 'dark', 'false', 'bar-shaped', 'false')
union_collinear_contours_xld (LinesXLD, UnionContours, 40, 3, 3, 0.2, 'attr_keep')
select_shape_xld (UnionContours, SelectedXLD, 'contlength', 'and', 15, 1000)
gen_region_contour_xld (SelectedXLD, RegionXLD, 'filled')
union1 (RegionXLD, RegionUnion)
dilation_circle (RegionUnion, RegionScratches, 10.5)
*
* Display the results
dev_set_draw ('margin')
dev_set_line_width (3)
dev_set_colored (12)
dev_display (Image)
dev_display (RegionScratches)

HALCON表面划痕检测相关推荐

  1. 缺陷检测——Halcon表面划痕检测

    一.项目场景: 提取表面划痕缺陷 二.解决方案: 1.先对原始图像做中值滤波处理: 2.局部阈值处理 3.blob分析提取特征 三.halcon代码 read_image (Image, 'scrat ...

  2. 机器视觉表面划痕检测流程

    表面缺陷检测常见的检测主要有物体表面的划痕.污渍.缺口.平面度.破损.边框对齐度.物体表面的亮度.皱纹.斑点.孔等. 表面缺陷检测设备凝聚了机器视觉领域的许多技术成果,吸取了许多创新的检测理念,可以与 ...

  3. halcon机器视觉实例1--表面划痕检测

    前言 这个是开始halcon机器视觉的第一篇. 为什么要用halcon呢,因为有很多现成的算子,方便快速应用. 后续的计划是一边熟悉halcon,一边刷刚萨雷斯的<数字图像处理>. 正文 ...

  4. 基于Halcon学习的缺陷检测【四】光伏电池片的指纹以及划痕检测【第一种方法】

    此例子主要是为了把光伏电池片的指纹以及划痕标注出来.  总代码: *读取图片 read_image (Image, 'E:/研究生学习/电池片练习/手指印/截图.png') *清除窗口 dev_cle ...

  5. 基于Halcon学习的缺陷检测【五】光伏电池片的指纹以及划痕检测【第二种方法】

     此例子主要是为了把光伏电池片的指纹以及划痕标注出来. 总代码:  *读取图片 read_image (Image, 'E:/研究生学习/电池片练习/手指印/截图.png')*清除窗口 dev_cle ...

  6. 圆环划痕检测halcon

    文章目录 处理要求 处理源码 处理效果 博主写作不容易,孩子需要您鼓励 万水千山总是情 , 先点个赞行不行 处理要求 查找圆环缺陷 处理源码 read_image (Image, 'F:/HALCON ...

  7. halcon视觉缺陷检测系列(1)常用的6种方法

    一.缺陷检测综述 缺陷检测是视觉需求中难度最大一类需求,主要是其稳定性和精度的保证.首先常见缺陷:凹凸.污点瑕疵.划痕.裂缝.探伤等.常用的手法有六大金刚(在halcon中的ocv和印刷检测是针对印刷 ...

  8. 基于机器视觉的磁头飞机载划痕检测

    基于机器视觉的磁头飞机载划痕检测 磁头飞机载的外观划痕检测,这个在磁盘企业里应用比较多.一般需要检测磁头表面是否有划痕.属于外观检测的一种.比较难的一类项目.不过好的是,磁头飞机载都是平面的,照明比较 ...

  9. 基于机器视觉的IC表面字符检测

    基于机器视觉的IC表面字符检测 IC表面字符识别,这个在半导体行业里是经常遇到的视觉检测应用项目.一般需要检测其型号.批号等内容.丝印外观可能会比较少检测,要求没有这么高. 低角度环形光源 工业光源 ...

最新文章

  1. Linux服务管理---系统运行级别、rpm启动与自启动、源码包的启动...
  2. 获取url的hash值
  3. Codeforces 988F. Rain and Umbrellas
  4. WebSphere Application Server v6中的问题诊断以及日志策略
  5. Delphi 的字符及字符串[4] - 字符串、字符指针与字符数组
  6. 学习心得——李嫣然、逯广捷
  7. Android:ListView
  8. 编译c语言源程序得到的目标文件可以直接在dos环境中运行,c语言练习题一.doc
  9. 记一次 GitHub 出现 ^M 符号的解决办法
  10. MAC下安装与配置MySQL [转]
  11. 从 Google 代码库找到的好东西【web开发方面】
  12. 14_python_练习题——excel操作
  13. visio用例图箭头怎么画_解析用Visio画UML用例图简明步骤
  14. java 数独算法_[Java] 数独生成和求解
  15. 压力换算公斤单位换算_常用压力单位换算表
  16. AUC与ROC曲线面积的意义(细扒sklearn的AUC计算方法)
  17. 电脑通话有回音解决方案 使用电脑通话时有回音(可以听到对方电脑中自己说话的声音)电脑通话回音解决方案【以Thinkpad Win10系统为例】
  18. 一大波能提高编程技能的游戏
  19. css 屏幕背景图片 img.html
  20. python实现学员管理系统(增删改查)

热门文章

  1. 大唐联仪推出下一代移动通信测试解决方案
  2. 高速学会Mac上托管代码到github(具体解释)
  3. Entity Framework 6 Recipes 2nd Edition(10-6)译 - TPT继承模型中使用存储过程
  4. Entity Framework 6 Recipes 2nd Edition(9-1)译-用Web Api更新单独分离的实体
  5. [Objective-C] 如何定义Block(块)
  6. 【译文】 C#面向对象的基本概念 (Basic C# OOP Concept) 第一部分(类,对象,变量,方法,访问修饰符)...
  7. 通过变长数组(VLA)来看编译器的不同
  8. 使用HtmlGenericControl控件动态产生一些HtmlControls
  9. Ogre貌似开始推荐MYGUI了~~
  10. DS18B20 理解与操作源码