halcon缺陷检测blob分析案例

2023-12-22 13:52:13
* This example demonstrates a quality inspection on hazelnut wavers.
* Using the morphology tools the waver is extracted and examined
* according to a few shape features like Rectangularity and AreaHoles.
* This program also shows the use of the operator area_holes.
* 
read_image (Image, 'food/hazelnut_wafer_01')
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_update_window ('off')
dev_set_line_width (3)
dev_set_draw ('margin')
set_display_font (WindowHandle, 20, 'mono', 'true', 'false')
* 
for Index := 1 to 24 by 1
    read_image (Image, 'food/hazelnut_wafer_' + Index$'.02')
    binary_threshold (Image, Foreground, 'smooth_histo', 'light', UsedThreshold)
    opening_circle (Foreground, FinalRegion, 8.5)
    area_holes (FinalRegion, AreaHoles)
    rectangularity (FinalRegion, Rectangularity)
    dev_display (Image)
    *根据孔洞数或者矩形度来判断是否是ok
    if (AreaHoles > 300 or Rectangularity < 0.92)
        dev_set_color ('red')
        Text := 'Not OK'
    else
        dev_set_color ('forest green')
        Text := 'OK'
    endif
    dev_display (FinalRegion)
    disp_message (WindowHandle, Text, 'window', 12, 12, '', 'false')
    if (Index < 24)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
 * fin.hdev: Detection of a fin
* 
dev_update_window ('off')
read_image (Fins, 'fin' + [1:3])
get_image_size (Fins, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width[0], Height[0], 'black', WindowID)
set_display_font (WindowID, 14, 'mono', 'true', 'false')
for I := 1 to 3 by 1
    select_obj (Fins, Fin, I)
    dev_display (Fin)
    binary_threshold (Fin, Background, 'max_separability', 'light', UsedThresho

文章来源:https://blog.csdn.net/weixin_38241876/article/details/135150646
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。