基于Halcon学习的一维码识别【三】barcode.orientation.hdev

识别条形码每次旋转后的图片,并得到识别的结果


总代码: 

*读取图片
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')
* 


*创建一个条形码阅读器的模型。
*'element_size_min'条码最小尺寸(宽度和间距)指 黑条或者白条的最小尺寸像素是1.5像素
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)
    *寻找条形码并且进行识别,第四个参数可以选择auto,自动确定码制
    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')
    *如果小于360度继续旋转
    if (Rot < 360)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
* 清除模型的句柄
clear_bar_code_model (BarCodeHandle)

逐段分析:

*读取图片
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')

*创建一个条形码阅读器的模型。
*'element_size_min'条码最小尺寸(宽度和间距)指 黑条或者白条的最小尺寸像素是1.5像素
create_bar_code_model ('element_size_min', 1.5, BarCodeHandle)

*每30度进行一次旋转
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)

    *寻找条形码并且进行识别,第四个参数可以选择auto,自动确定码制
    find_bar_code (ImageRotate, SymbolRegions, BarCodeHandle, 'EAN-13', DecodedDataStrings)
    dev_display (SymbolRegions)

    *得到条形码的角度
    get_bar_code_result (BarCodeHandle, 'all', 'orientation', Orientation)

     *画出一个箭头
    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')
    
*如果小于360度继续旋转
    if (Rot < 360)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor

* 清除模型的句柄
clear_bar_code_model (BarCodeHandle)

 旋转后的图像:

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值