翻譯|行業資訊|編輯:胡濤|2023-08-09 11:11:42.053|閱讀 159 次
概述:在這篇博文中,我們將學習如何構建高性能的Python 條形碼閱讀器
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.BarCode for .NET 是一個功能強大的API,可以從任意角度生成和識別多種圖像類型的一維和二維條形碼。開發人員可以輕松添加條形碼生成和識別功能,以及在.NET應用程序中將生成的條形碼導出為高質量的圖像格式。
Aspose API支持流行文件格式處理,并允許將各類文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
條形碼是機器可讀的數據表示形式,由平行線或幾何圖案直觀地表示。它們提供了一種快速準確的方法來存儲和檢索信息,例如產品詳細信息、庫存代碼或跟蹤號碼。條形碼有多種類型,包括 UPC、EAN、QR 碼等。每種類型都有特定的結構和編碼機制。在這篇博文中,我們將學習如何構建高性能的Python 條形碼閱讀器。附有代碼示例的 Python 教程將向您展示如何掃描條形碼。
我們將使用來掃描和讀取條形碼。它是一個條形碼生成和識別庫,允許您向 Python 應用程序添加條形碼功能。它提供簡單直觀的 API 來生成和識別各種類型的條形碼,包括 QR 碼、Code 128、EAN-13、UPC-A 等。使用 Aspose.BarCode for Python,您可以輕松生成條形碼圖像、自定義其外觀以及從圖像或掃描文檔中讀取條形碼。它是將條形碼功能集成到 Python 項目中的強大工具。
請下載Python Barcode庫包或在控制臺中使用以下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
同樣,我們按照前面提到的步驟掃描并讀取文檔中可用的多個條形碼。
以下代碼示例展示了如何使用 Python 從圖像中讀取多個條形碼。
# 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
我們可以按照以下步驟指定各種質量設置來讀取扭曲、損壞或低質量的條形碼圖像:
以下代碼示例演示如何指定 Python 條形碼掃描儀的質量設置。
# 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 中掃描條碼,希望能幫到您,除此之外,你有其他方面的需求,也歡迎和我們互動,或這下體驗~
歡迎下載|體驗更多Aspose產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn