Halcon識別旋轉的一維碼

原圖

識別結果:

代碼:

* 
* Orientation with reading direction of a bar code
* 
read_image (Image, 'barcode/ean13/ean1305')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
dev_set_color ('green')
dev_set_draw ('margin')
dev_set_line_width (3)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
* 
create_bar_code_model ('element_size_min', 1.5, BarCodeHandle)
for Rot := 0 to 360 by 30
    rotate_image (Image, ImageRotate, Rot, 'weighted')
    dev_display (ImageRotate)
    get_image_size (ImageRotate, Width, Height)
    dev_set_window_extents (0, 0, Width, Height)
    find_bar_code (ImageRotate, SymbolRegions, BarCodeHandle, 'EAN-13', DecodedDataStrings)
    dev_display (SymbolRegions)
    get_bar_code_result (BarCodeHandle, 'all', 'orientation', Orientation)
    area_center (SymbolRegions, Area, Row, Col)
    gen_arrow_contour_xld (Arrow, Row + sin(rad(Orientation)) * 70, Col - cos(rad(Orientation)) * 70, Row - sin(rad(Orientation)) * 70, Col + cos(rad(Orientation)) * 70, 25, 25)
    dev_display (Arrow)
    disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'true')
    if (Rot < 360)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
* 
clear_bar_code_model (BarCodeHandle)

 

 

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