[机器视觉]halcon十二 条码识别、字符识别之一维码识别

[机器视觉]halcon十二 条码识别、字符识别之一维码识别

流程

        获取图像-》创建模型-》条码识别-》清除模型

算子

        create_bar_code_model : 创建模型

        find_bar_code : 查找条码

        clear_bar_code_model : 销毁

        get_bar_code_result : 获取一维码读取内容

        get_bar_code_object : 获取一维码读取区域

        set_bar_code_param : 设置一维码模型参数 

代码

        

*读取图片
read_image(Image, 'C:/Users/Public/Documents/MVTec/HALCON-17.12-Progress/examples/images/barcode/code128/code128_max_diff_orient.png')
*创建模型 这里使用默认参数
create_bar_code_model ([], [], BarCodeHandle)
*查找条码
*DecodedDataStrings (输出参数)解码结果
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings)
*获取条码区域
get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
*获取一维码读取内容
get_bar_code_result (BarCodeHandle, 'all', 'decoded_types', BarCodeResults)
*销毁
clear_bar_code_model (BarCodeHandle)

多文件检测

*获取窗口句柄对象
dev_get_window (WindowHandle)
*读取图片
read_image(Image, 'C:/Users/Public/Documents/MVTec/HALCON-17.12-Progress/examples/images/barcode/code128/code128_max_diff_orient.png')
*创建模型 这里使用默认参数
create_bar_code_model ([], [], BarCodeHandle)
*图片文件夹
imageDir := 'C:/Users/Public/Documents/MVTec/HALCON-17.12-Progress/examples/images/barcode/code128/'
 
*获取文件列表
list_files (imageDir, ['files','follow_links','recursive'], ImageFiles)
 
*可以用for算子把文件一个一个打开
for Index := 0 to |ImageFiles| - 1 by 1
    *从文件集合中获取指定索引的数据
    imagePath := ImageFiles[Index]    
    *判断文件是否存在,存在返回true,否则返回false
    *imagePath 输入参数:要判断的文件路径
    *FileExists 输出参数: 输出文件是否存在,存在返回true,否则返回false
    file_exists (imagePath, FileExists)
    
    if (FileExists)        
        *读取图片
        read_image (Image, imagePath)  
        get_image_size (Image, Width, Height)
        *创建模型 这里使用默认参数
        create_bar_code_model ([], [], BarCodeHandle)
        *查找条码
        *DecodedDataStrings (输出参数)解码结果
        find_bar_code (Image, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings)
        *获取条码区域
        get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
        *获取一维码读取内容
        get_bar_code_result (BarCodeHandle, 'all', 'decoded_types', BarCodeResults)
    else
        disp_message (WindowHandle, '图片-不存在->路径:'+imagePath, 'window', 12, 12, 'black', 'true')
    endif
endfor
*销毁
clear_bar_code_model (BarCodeHandle)

  • 7
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

StevenChen85

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值