-
Halcon
学习笔记之缺陷检测
(
一
)
例程:
surface_
说明:这个程序利用局部阈值和形态学处理提取表面划痕
p>
代码中绿色部分为个人理解和注释
,
其余为
例程中原有代码
*surface_:extraction
of
surface
scratches
via
local
thresholding
and
morphological
post-
processing*
dev_close_window()
dev_updat
e_window(
‘
off
’
)
*****
*step:
acquire image
//
获取图片
*****
read_image(Image,
’
surface_scratch
’
)
//
读入图片名为
’
surface_scratch
’的图片
< br>
get_image_size(Image,Width,Height)
//
获取图像的尺寸:宽、高
//
在坐标为(
0,0
)处打开一个图像窗口。其宽和高分别是
Width
和
Width
,窗口的句柄为
WindowID
dev_open_window_fit_image(Image,0,0,Wid
th,Width,WindowID)
//
设置窗口中显示
的字体颜色,大小,加粗,倾斜
set_display_f
ont(WindowID,12,
’
Courier
’
,
’
true
’
,
’
false<
/p>
’
)
dev_set_draw(
p>
‘
margin
’
)
//
设置区域填充类型:
’
margin
’
or
‘
fill
’
dev_set_line_width(4)
//
设置
线宽,这个在填充类型为
fill
时效果不明显
dev_display(Image)
//
显示图片
disp_continue_message(WindowID,
’
black
’
,
’
true
’
)
//
显示
继续消息,等待用户按
F5
继续执行
stop()
*****
*step: segment image
*****
*-> using a local threshold
mean_image(Image,ImageMean,7,7)
//
用
7<
/p>
×
7
的窗口对图像进行均
值滤波
dyn_threshold(Image,
ImageMean,DarkPixels,5,
’
dark
’
)
//
利用本地阈值进行图像分割
*->extract connected
components
connection(DarkPixels,ConnectedRegions)
//
对区域进行连通运算
dev_set_colored(12)
//
设置区域显示的颜色数目
dev_display(ConnectedRegions)
//
显示图像
?
disp_continue_message(WindowID,
’
black
’
,
’
true
’
)
?
//
显示继续提示,提示继续
stop()
-
-
-
-
-
-
-
-
-
上一篇:外事英语荟萃
下一篇:第四讲 词义猜测题——上下文中求答案