您的位置:首页 > 其它

halcon例程学习笔记(7)---检测漏焊board.hdev

2013-10-09 17:11 246 查看
通过本例程学习,掌握了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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: