halcon python缺陷检测_Halcon学习笔记之缺陷检测(一)

*surface_scratch.hdev:extraction of surface scratches via local thresholding and morphological post-processing*

dev_close_window()

dev_update_window(‘off’)

*****

*step: acquire image //获取图片

*****

read_image(Image,’surface_scratch’) //读入图片名为’surface_scratch’的图片

get_image_size(Image,Width,Height) //获取图像的尺寸:宽、高

//在坐标为(0,0)处打开一个图像窗口。其宽和高分别是Width和Width,窗口的句柄为WindowID

dev_open_window_fit_image(Image,0,0,Width,Width,WindowID)

//设置窗口中显示的字体颜色,大小,加粗,倾斜

set_display_font(WindowID,12,’Courier’,’true’,’false’)

dev_set_draw(‘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×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()

*****

*step: process regions

*****

*->select large regions

select_shape(ConnectedRegions,SelsectedRegions,’area’,’and’,10,1000) //区域选择,用面积的形态特征选择面积在10到10000间的区域

dev_display(Image) //显示原图

dev_display(SelectedRegions) //显示选择的区域

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_set_colored类似

dev_display(Image) //显示原图

dev_display(SelectedRegions) //显示选中的区域图

disp_continue_message(WindowID,’black’,’true’) //显示继续提示信息

stop()

*->merge fractioned scratches via morphology

union1(SelectedRegions,RegionUnion) //合并所有区域

dilation_circle(RegionUnion,RegionDilation,3.5) //用半径3.5 的掩膜进行膨胀

dev_display(Image) //显示原图

dev_display(RegionDilation) //显示膨胀后的区域图

disp_continue_message(WindowID,’black’,’true’)//显示继续提示信息

stop()

skeleton(RegionDialtion,Skeleton) //计算区域的中轴,见例程:surface_scratch.hdev

connection(Skeleton,Errors) //连通操作,以便后面进行区域选择

dev_set_colored(12) //设置颜色

dev_display(Image) //显示原图

dev_display(Errors) //显示所有抓痕

disp_continue_message(WindowID,’black’,’true’) //显示继续提示信息

stop()

*->distinguish small and large scratches

close_zoom_window(WindowHandleZoom,Width,Height) //关闭缩放窗口

select_shape(Errors,Scratches,’area’,’and’,50,10000)//选择区域面积在50到10000的作为划痕

select_shape(Errors,Dots,’area’,’and’,1,50) //选择区域面积在1到50 的作为点

dev_display(Image) //显示原图

dev_set_color(‘red’) //设置区域显示颜色为红色

dev_display(Scratches) //显示条状划痕(显示为红色)

dev_set_color(‘blue’) //设置区域显示颜色蓝色

dev_display(Dots) //显示点状划痕(显示为蓝色)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值