翻譯|使用教程|編輯:莫成敏|2020-06-12 15:29:42.417|閱讀 284 次
概述:在本文中,將以Code39為例,演示如何使用Dynamsoft Barcode Reader SDK解碼非標(biāo)準(zhǔn)一維條形碼。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
Dynamsoft Barcode Reader SDK一款多功能的條碼讀取控件,只需要幾行代碼就可以將條碼讀取功能嵌入到Web或桌面應(yīng)用程序。這可以節(jié)省數(shù)月的開(kāi)發(fā)時(shí)間和成本。能支持多種圖像文件格式以及從攝像機(jī)或掃描儀獲取的DIB格式。使用Dynamsoft Barcode Reader SDK,你可以創(chuàng)建強(qiáng)大且實(shí)用的條形碼掃描儀軟件,以滿(mǎn)足你的業(yè)務(wù)需求。
點(diǎn)擊下載Dynamsoft Barcode Reader最新版
起始字符和終止字符被定義為線(xiàn)性條形碼(一維條形碼)標(biāo)準(zhǔn)的一部分。但是,您可能會(huì)遇到一些非標(biāo)準(zhǔn)的一維條碼符號(hào),其中開(kāi)始和結(jié)束字符有所更改。在本文中,我將以Code39為例,演示如何使用Dynamsoft Barcode Reader SDK解碼非標(biāo)準(zhǔn)一維條形碼。
開(kāi)發(fā)環(huán)境
Python條碼SDK安裝
Dynamsoft條形碼閱讀器SDK僅支持Python3.x。
pip install dbr
非標(biāo)準(zhǔn)一維條形碼識(shí)別
為了進(jìn)行比較,我準(zhǔn)備了三個(gè)Code39圖像,它們的起始和終止字符不同。
標(biāo)準(zhǔn)代碼39符號(hào)(*)
非標(biāo)準(zhǔn)Code39符號(hào)體系(+)
非標(biāo)準(zhǔn)Code39符號(hào)體系(-)
以下是用于解碼標(biāo)準(zhǔn)一維條形碼圖像的代碼段:
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)
運(yùn)行代碼之前,您需要獲得免費(fèi)的試用許可證。
如果您使用非標(biāo)準(zhǔn)的1D條形碼符號(hào)符號(hào)運(yùn)行代碼,則沒(méi)有結(jié)果。根據(jù)在線(xiàn)文檔,非標(biāo)準(zhǔn)條形碼在EnumBarcodeFormat_2中定義為擴(kuò)展格式。
因此,您需要對(duì)上面的代碼進(jìn)行一些更改:
print(text_result.barcode_format_string_2)
另外,您必須設(shè)置與條形碼類(lèi)型相關(guān)的開(kāi)始和結(jié)束字符。一種簡(jiǎn)單的方法是加載JSON格式的參數(shù)模板文件:
{ "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" }
對(duì)于非標(biāo)準(zhǔn)條形碼,您只需要修改以下部分:
"StandardFormat": "BF_CODE_39", "HeadModuleRatio": "131113131", "TailModuleRatio": "131113131"
通過(guò)引用Code39字符表,“ 131113131”代表“ +”,“ 131111313”代表“ -”。
現(xiàn)在,您可以創(chuàng)建一個(gè)自定義模板文件并以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])
運(yùn)行我的Python代碼以讀取標(biāo)準(zhǔn)和非標(biāo)準(zhǔn)Code39條形碼:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: