Halcon 读取工业条形码

上图:
在这里插入图片描述

贴上代码:

* 读取2/5类型工业条形码
create_bar_code_model ([], [], BarCodeHandle)
*检测一张图片上的单一条形码
set_bar_code_param (BarCodeHandle, 'stop_after_result_num', 1)

* Some codes show a minimal code length of 1 digit. Hence, we need to decrease the
* default setting for this application.
set_bar_code_param_specific (BarCodeHandle, '2/5 Industrial', 'min_code_length', 1)
*关闭窗口
dev_close_window ()
*重新打开一个窗口
dev_open_window (0, 0, 120, 300, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
for I := 1 to 4 by 1
    read_image (Image, 'barcode/25industrial/25industrial0' + I)
    get_image_size (Image, Width, Height)
    dev_set_window_extents (0, 0, Width - 1, Height - 1)
    dev_display (Image)
    dev_set_color ('green')
    * Read bar code, the resulting string includes the check character
    set_bar_code_param (BarCodeHandle, 'check_char', 'absent')
    find_bar_code (Image, SymbolRegions, BarCodeHandle, '2/5 Industrial', DecodedDataStrings)
    disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'false')
    LastChar := strlen(DecodedDataStrings) - 1
    disp_message (WindowHandle, sum(gen_tuple_const(LastChar,' ')) + DecodedDataStrings{LastChar}, 'window', 12, 12, 'forest green', 'false')
    stop ()
    * Read bar code using the check character to check the result, i.e.,
    * the check character does not belong to the returned string anymore.
    * If the check character is not correct, the bar code reading fails
    dev_set_color ('green')
    set_bar_code_param (BarCodeHandle, 'check_char', 'present')
    find_bar_code (Image, SymbolRegions, BarCodeHandle, '2/5 Industrial', DecodedDataStrings)
    disp_message (WindowHandle, DecodedDataStrings, 'window', 36, 12, 'black', 'false')
    dev_set_color ('magenta')
    if (I < 4)
        stop ()
    endif
endfor

算子回顾

find_bar_code 检测并读取图像中的条形码符号

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章