翻譯|行業(yè)資訊|編輯:胡濤|2023-08-09 11:11:42.053|閱讀 159 次
概述:在這篇博文中,我們將學(xué)習(xí)如何構(gòu)建高性能的Python 條形碼閱讀器
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.BarCode for .NET 是一個(gè)功能強(qiáng)大的API,可以從任意角度生成和識(shí)別多種圖像類型的一維和二維條形碼。開發(fā)人員可以輕松添加條形碼生成和識(shí)別功能,以及在.NET應(yīng)用程序中將生成的條形碼導(dǎo)出為高質(zhì)量的圖像格式。
Aspose API支持流行文件格式處理,并允許將各類文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
條形碼是機(jī)器可讀的數(shù)據(jù)表示形式,由平行線或幾何圖案直觀地表示。它們提供了一種快速準(zhǔn)確的方法來存儲(chǔ)和檢索信息,例如產(chǎn)品詳細(xì)信息、庫存代碼或跟蹤號碼。條形碼有多種類型,包括 UPC、EAN、QR 碼等。每種類型都有特定的結(jié)構(gòu)和編碼機(jī)制。在這篇博文中,我們將學(xué)習(xí)如何構(gòu)建高性能的Python 條形碼閱讀器。附有代碼示例的 Python 教程將向您展示如何掃描條形碼。
我們將使用來掃描和讀取條形碼。它是一個(gè)條形碼生成和識(shí)別庫,允許您向 Python 應(yīng)用程序添加條形碼功能。它提供簡單直觀的 API 來生成和識(shí)別各種類型的條形碼,包括 QR 碼、Code 128、EAN-13、UPC-A 等。使用 Aspose.BarCode for Python,您可以輕松生成條形碼圖像、自定義其外觀以及從圖像或掃描文檔中讀取條形碼。它是將條形碼功能集成到 Python 項(xiàng)目中的強(qiáng)大工具。
請下載Python Barcode庫包或在控制臺(tái)中使用以下pip命令從安裝API :
pip install aspose-barcode-for-python-via-net
我們可以按照以下步驟掃描并讀取條形碼:
以下代碼示例展示了如何使用 Python 從圖像中讀取條形碼。
# This code example demonstrates how to scan and read barcode from an image in Python. # Image path full_path = "C:\\Files\\barcode.jpg" # Initialize a Barcode Reader reader = barcoderecognition.BarCodeReader(full_path) # Read barcodes recognized_results = reader.read_bar_codes() # Display results for x in recognized_results: print("Code text: " + x.code_text) print("Barcode type: " + x.code_type_name)
Code text: 1234567890 Barcode type: Code39Standard
同樣,我們按照前面提到的步驟掃描并讀取文檔中可用的多個(gè)條形碼。
以下代碼示例展示了如何使用 Python 從圖像中讀取多個(gè)條形碼。
# This code example demonstrates how to scan and read multiple barcodes from an image in Python. # Image path full_path = "C:\\Files\\barcodes_different_quality.png" # Initialize a Barcode Reader reader = barcoderecognition.BarCodeReader(full_path) # Read barcodes recognized_results = reader.read_bar_codes() # Display results for x in recognized_results: print(x.code_text) print(x.code_type_name) print("------------------------------")
Code text: Aspose Code 04 Barcode type: Code128 ------------------------------ Code text: Aspose Regular Barcode type: Aztec ------------------------------ Code text: /YYAD25HL Barcode type: Code39Standard ------------------------------ Code text: 7894706 Barcode type: Matrix2of5 ------------------------------ Code text: D19-WQ9-F91046-0811 Barcode type: DataMatrix ------------------------------ Code text: 0058 Barcode type: Code39Standard ------------------------------ Code text: 990000837284 Barcode type: Planet ------------------------------
我們可以按照以下步驟掃描讀取指定的條碼類型:
以下代碼示例展示了如何在 Python 中掃描和讀取特定條形碼類型。
# This code example demonstrates how to scan and read a specific barcode type from an image in Python. # Image path full_path = "C:\\Files\\Code_128.png" # Initialize a Barcode Reader # Specify decode type to read a specific barcode type reader = barcoderecognition.BarCodeReader(full_path, barcoderecognition.DecodeType.CODE128) # Read barcodes recognized_results = reader.read_bar_codes() # Display results for x in recognized_results: print("Code text: " + x.code_text) print("Barcode type: " + x.code_type_name)
Code text: 1234567890 Barcode type: Code128
我們可以按照以下步驟指定各種質(zhì)量設(shè)置來讀取扭曲、損壞或低質(zhì)量的條形碼圖像:
以下代碼示例演示如何指定 Python 條形碼掃描儀的質(zhì)量設(shè)置。
# This code example demonstrates how to specify quality settings while scanning and reading barcodes in Python. # Image path full_path = "C:\\Files\\barcodes_different_quality.png" # Initialize a Barcode Reader reader = barcoderecognition.BarCodeReader(full_path) # Specify Quality Settings reader.quality_settings = barcoderecognition.QualitySettings.high_performance reader.quality_settings.allow_median_smoothing = True reader.quality_settings.median_smoothing_window_size = 5 # Read barcodes recognized_results = reader.read_bar_codes() # Display results for x in recognized_results: print(x.code_text) print(x.code_type_name) print("------------------------------")
以上便是如何借助Aspose.BarCode,在 Python 中掃描條碼,希望能幫到您,除此之外,你有其他方面的需求,也歡迎和我們互動(dòng),或這下體驗(yàn)~
歡迎下載|體驗(yàn)更多Aspose產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn