如何使用Dynamsoft Barcode Reader SDK读取非标准一维条码

Dynamsoft Barcode Reader SDK一款多功能的条码读取控件,只需要几行代码就可以将条码读取功能嵌入到Web或桌面应用程序。这可以节省数月的开发时间和成本。能支持多种图像文件格式以及从摄像机或扫描仪获取的DIB格式。使用Dynamsoft Barcode Reader SDK,你可以创建强大且实用的条形码扫描仪软件,以满足你的业务需求。

Dynamsoft Barcode Reader最新版

开发环境

  • Python 3.x

Python条码SDK安装

Dynamsoft条形码阅读器SDK仅支持Python3.x。

pip install dbr

非标准一维条形码识别

为了进行比较,我准备了三个Code39图像,它们的起始和终止字符不同。

标准代码39符 (*)

如何使用Dynamsoft Barcode Reader SDK读取非标准一维条码

非标准Code39符 体系(+)

如何使用Dynamsoft Barcode Reader SDK读取非标准一维条码

非标准Code39符 体系(-)

如何使用Dynamsoft Barcode Reader SDK读取非标准一维条码

以下是用于解码标准一维条形码图像的代码段:

from dbr import *license_key = "LICENSE-KEY" #https://www.dynamsoft.com/CustomerPortal/Portal/Triallicense.aspxreader = BarcodeReader()reader.init_license(license_key)try:    text_results = reader.decode_file(filename)    if text_results != None:        for text_result in text_results:            print('Barcode Format:')            print(text_result.barcode_format_string)            print('')            print('Barcode Text:')            print(text_result.barcode_text)            print('')            print('Localization Points:')            print(text_result.localization_result.localization_points)            print('------------------------------------------------')            print('')except BarcodeReaderError as bre:    print(bre)

运行代码之前,您需要获得免费的试用许可证。

如果您使用非标准的1D条形码符 符 运行代码,则没有结果。根据在线文档,非标准条形码在EnumBarcodeFormat_2中定义为扩展格式。

如何使用Dynamsoft Barcode Reader SDK读取非标准一维条码

因此,您需要对上面的代码进行一些更改:

print(text_result.barcode_format_string_2)

另外,您必须设置与条形码类型相关的开始和结束字符。一种简单的方法是加载JSON格式的参数模板文件:

{  "ImageParameter": {    "BarcodeFormatIds_2": [ "BF2_NONSTANDARD_BARCODE" ],    "FormatSpecificationNameArray": [ "FormatSpecification1" ],    "DeblurLevel": 9,    "Description": "",    "ExpectedBarcodesCount": 0,    "LocalizationModes": [      {        "Mode": "LM_CONNECTED_BLOCKS"      },      {        "Mode": "LM_SCAN_DIRECTLY",        "ScanStride": 0      },      {        "Mode": "LM_STATISTICS"      },      {        "Mode": "LM_LINES"      }    ],    "Name": "Test",    "Timeout": 1000000  },  "FormatSpecification": {    "Name": "FormatSpecification1",    "BarcodeFormatIds_2": [ "BF2_NONSTANDARD_BARCODE" ],    "StandardFormat": "BF_CODE_39",    "HeadModuleRatio": "131113131",    "TailModuleRatio": "131113131"  },  "Version": "3.0"}

对于非标准条形码,您只需要修改以下部分:

"StandardFormat": "BF_CODE_39","HeadModuleRatio": "131113131","TailModuleRatio": "131113131"
  • StandardFormat:条形码符
  • HeadModuleRatio:起始字符
  • TailModuleRatio:停止符

通过引用Code39字符表,“ 131113131”代表“ +”,“ 131111313”代表“ -”。

现在,您可以创建一个自定义模板文件并以Python代码加载它:

json_file = Noneif special_character == '+':    json_file = r"template_plus.json"if special_character == '-':    json_file = r"template_minus.json"if json_file == None:    returnerror = reader.init_runtime_settings_with_file(json_file)if error[0] != EnumErrorCode.DBR_OK:    print(error[1])

运行我的Python代码以读取标准和非标准Code39条形码:

如何使用Dynamsoft Barcode Reader SDK读取非标准一维条码


想要购买Dynamsoft Barcode Reader正版授权,或了解更多产品信息请点击【咨询在线客服】

如何使用Dynamsoft Barcode Reader SDK读取非标准一维条码

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年5月9日
下一篇 2020年5月9日

相关推荐

发表回复

登录后才能评论