翻譯|使用教程|編輯:莫成敏|2020-06-12 15:29:42.417|閱讀 284 次
概述:在本文中,將以Code39為例,演示如何使用Dynamsoft Barcode Reader SDK解碼非標準一維條形碼。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Dynamsoft Barcode Reader SDK一款多功能的條碼讀取控件,只需要幾行代碼就可以將條碼讀取功能嵌入到Web或桌面應用程序。這可以節省數月的開發時間和成本。能支持多種圖像文件格式以及從攝像機或掃描儀獲取的DIB格式。使用Dynamsoft Barcode Reader SDK,你可以創建強大且實用的條形碼掃描儀軟件,以滿足你的業務需求。
點擊下載Dynamsoft Barcode Reader最新版
起始字符和終止字符被定義為線性條形碼(一維條形碼)標準的一部分。但是,您可能會遇到一些非標準的一維條碼符號,其中開始和結束字符有所更改。在本文中,我將以Code39為例,演示如何使用Dynamsoft Barcode Reader SDK解碼非標準一維條形碼。
開發環境
Python條碼SDK安裝
Dynamsoft條形碼閱讀器SDK僅支持Python3.x。
pip install dbr
非標準一維條形碼識別
為了進行比較,我準備了三個Code39圖像,它們的起始和終止字符不同。
標準代碼39符號(*)
非標準Code39符號體系(+)
非標準Code39符號體系(-)
以下是用于解碼標準一維條形碼圖像的代碼段:
from dbr import * license_key = "LICENSE-KEY" # //www.dynamsoft.com/CustomerPortal/Portal/Triallicense.aspx reader = 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中定義為擴展格式。
因此,您需要對上面的代碼進行一些更改:
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"
通過引用Code39字符表,“ 131113131”代表“ +”,“ 131111313”代表“ -”。
現在,您可以創建一個自定義模板文件并以Python代碼加載它:
json_file = None if special_character == '+': json_file = r"template_plus.json" if special_character == '-': json_file = r"template_minus.json" if json_file == None: return error = reader.init_runtime_settings_with_file(json_file) if error[0] != EnumErrorCode.DBR_OK: print(error[1])
運行我的Python代碼以讀取標準和非標準Code39條形碼:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: