视觉进阶:检测漏焊board.hdev

通过本例程学习,掌握了read_image读取多幅图像,channels_to_image算子的使用。

本例程的算法思路是通过求取各个通道求取暗的和亮的部分,然后各个通道使用union1进行联合,得到的联合后的暗图像和明亮图像,然后求取明暗图像的交集。

后续经过基本的选择处理,得到漏焊的焊点。


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 ()
*获取4个通道的均值图像
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 ()
dev_clear_window()
dev_display (Intersection)
dev_clear_window()
dev_display (Back)
dev_clear_window()
expand_region (Intersection, Back, RegionExpanded, 10, 'image')
dev_clear_window()
dev_display (RegionExpanded)
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_clear_window()
dev_display (Rest)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*填充空白区域或者重叠区域的区域
expand_gray (Rest, Ic, Good, Bad, 6, 'image', 5)
dev_clear_window()
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)

image.png 

image.png

image.png

image.png


image.png

--------------------- 

作者:hackpig
来源:
www.skcircle.com
版权声明:本文为博主原创文章,转载请附上博文链接!



本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2025年4月    »
123456
78910111213
14151617181920
21222324252627
282930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864