halcon例程解析:在不同照明方向拍摄的图像中检测缺失焊料——board.hdev

该博客介绍了如何使用Halcon图像处理库在不同光照条件下检测焊接板上缺失的焊料。通过四张不同角度照明的图片,分别对暗区和亮区进行阈值分割,结合并集、交集和补集操作找出焊料区域。最后,通过差分操作确定缺失焊料的区域,实现精确检测。文章提供了详细的代码示例和步骤解析。
摘要由CSDN通过智能技术生成

halcon例程解析:在不同照明方向拍摄的图像中检测缺失焊料——board.hdev

为检测缺失焊料,分别采集四个方向打光的图像,利用这四张不同光照的图像来检测焊料的缺失

1. 效果展示

利用如下四张图像,检测是否焊料缺失

原图
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

结果
在这里插入图片描述

2. 思路分析

方案依据:

  • 需要焊料部分较暗

  • 有焊料部分,经过打光后边缘反光、较亮

  • 分割出要焊料区域,分割出有焊料区域,作差即为缺焊区域

思路如下:

  1. 分割要焊料区域
    1. 对每一张图进行阈值分割,取较暗区域
    2. 取并集得到
  2. 分割有焊料区域
    1. 对每一张图进行阈值分割,取较亮区域
    2. 取并集得到粗略边缘区域
    3. 与要焊料区域取交集,得到边缘区域
    4. 取要焊料区域的补集作为背景区域
    5. 依靠背景区域做抑制,填充边缘区域得到有焊料区域
  3. 要焊料区域与有焊料区域作差
  4. 后处理

2.1 分割要焊料区域

threshold (Images, Darks, 0, 40)
union1 (Darks, Dark)
fill_up (Dark, DarkFilled)
  1. 对每一张图进行阈值分割,取较暗区域
  2. 取并集得到
    在这里插入图片描述

2.2 分割有焊料区域

threshold (Images, Lights, 100, 255)
union1 (Lights, Light)
intersection (DarkFilled, Light, Intersection)
  1. 对每一张图进行阈值分割,取较亮区域
  2. 取并集得到粗略边缘区域
  3. 与要焊料区域取交集,得到边缘区域
    在这里插入图片描述
    在这里插入图片描述
complement (DarkFilled, Back)

expand_region (Intersection, Back, RegionExpanded, 10, 'image')
fill_up (RegionExpanded, Good)
  1. 取要焊料区域的补集作为背景区域
  2. 依靠背景区域做抑制,填充边缘区域得到有焊料区域
    在这里插入图片描述

2.3 要焊料区域与有焊料区域作差

difference (DarkFilled, Good, Rest)

expand_gray (Rest, Ic, Good, Bad, 6, 'image', 5)

在这里插入图片描述

3 完整代码

* board.hdev: Detection of missing solder
* 
get_system ('clip_region', Information)
set_system ('clip_region', 'true')
dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowID)
read_image (Images, ['ic0','ic1','ic2','ic3'])
channels_to_image (Images, Ic)
select_obj (Images, Input1, 1)
dev_display (Input1)
set_display_font (WindowID, 14, 'mono', 'false', 'false')
disp_continue_message (WindowID, 'black', 'true')
stop ()
select_obj (Images, Input2, 2)
dev_display (Input2)
disp_continue_message (WindowID, 'black', 'true')
stop ()
select_obj (Images, Input3, 3)
dev_display (Input3)
disp_continue_message (WindowID, 'black', 'true')
stop ()
select_obj (Images, Input4, 4)
dev_display (Input4)
disp_continue_message (WindowID, 'black', 'true')
stop ()
mean_n (Ic, ImageMean)
dev_display (ImageMean)
threshold (Images, Darks, 0, 40)
union1 (Darks, Dark)
fill_up (Dark, DarkFilled)
dev_set_color ('green')
dev_display (DarkFilled)
disp_continue_message (WindowID, 'black', 'true')
stop ()
threshold (Images, Lights, 100, 255)
union1 (Lights, Light)
intersection (DarkFilled, Light, Intersection)
dev_display (ImageMean)
dev_display (Intersection)
disp_continue_message (WindowID, 'black', 'true')
stop ()
complement (DarkFilled, Back)
dev_set_color ('red')
dev_display (Back)
disp_continue_message (WindowID, 'black', 'true')
stop ()
expand_region (Intersection, Back, RegionExpanded, 10, 'image')
fill_up (RegionExpanded, Good)
dev_display (ImageMean)
dev_set_color ('green')
dev_display (Good)
disp_continue_message (WindowID, 'black', 'true')
stop ()
difference (DarkFilled, Good, Rest)
dev_set_color ('red')
dev_display (Rest)
disp_continue_message (WindowID, 'black', 'true')
stop ()
expand_gray (Rest, Ic, Good, Bad, 6, 'image', 5)
dev_display (Bad)
disp_continue_message (WindowID, 'black', 'true')
stop ()
connection (Bad, ConnectedBad)
select_shape (ConnectedBad, BigBad, 'area', 'and', 150, 99999)
area_center (BigBad, AreaBad, Row, Column)
count_obj (BigBad, NumMissingSolder)
AreaMissingSolder := sum(AreaBad)
dev_display (Images)
dev_set_color ('green')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Good)
dev_set_color ('red')
dev_display (BigBad)
dev_set_draw ('fill')
dev_set_line_width (1)
dev_update_window ('on')
set_system ('clip_region', Information)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值