如何使用 Python 读取条形码

这个简短的主题重点介绍如何使用 Python Read Barcode。在 Python 条形码扫描仪 应用程序可以使用几个步骤和简单的 API 调用来开发。该应用程序可以在使用 Python3 和 JDK 配置的基于 Linux、Windows 或 macOS 的环境中使用。在下面的示例中,我们专注于读取少数 Barcode 类型。但是,该 API 能够读取 DecodeType 枚举器中定义的许多其他类型的条形码信息,包括 GS1 代码、128 代码、QR 代码等。

使用 Python 读取条形码的步骤

  1. 为 Python 设置 Python3 和 Aspose.BarCode 遵循指南
  2. 创建一个包含要读取的条形码解码类型的 DecodeTypes 数组
  3. 创建 BarCodeReader class 的对象并提供包含 Barcode 和 DecodeTypes 数组的图像文件路径
  4. 从图像中读取条形码
  5. 迭代从图像中读取的条形码信息以供进一步使用

为了阅读基于 Python 的条形码并遵守上述步骤。该过程首先通过配置开发环境开始,然后您将通过提供源条形码图像文件路径和包含条形码类型作为参数的 DecodeType 数组来使用 BarCodeReader 类实例。在后续步骤中,我们将读取 Barcode 信息,并通过循环循环打印读取的信息。您可以根据您的要求在您的应用程序中进一步处理读取的条码信息。

使用 Python 读取条形码的代码

from asposebarcode import Recognition, Assist
# Setting License to read Barcode
licenseReadBarCode = Assist.License()
licenseReadBarCode.setLicense("Aspose.Total.lic")
# Set the Decod Types for the Barcode
decodeTypes=[Recognition.DecodeType.PDF_417, Recognition.DecodeType.DATA_MATRIX,
Recognition.DecodeType.QR,Recognition.DecodeType.CODE_39_EXTENDED,
Recognition.DecodeType.CODE_128, Recognition.DecodeType.RM_4_SCC]
# Instantiate BarCodeReader to load the Barcode image and Decode types of Barcodes to identify
BarcodeReader = Recognition.BarCodeReader("multiple_codes.png",None, decodeTypes)
# Read the Barcodes
results = BarcodeReader.readBarCodes()
# Print the read Barcodes information
print("ReadSimpleExample:")
i = 0
while (i < len(results)):
print(i)
print("code text: " + results[i].getCodeText())
print("code type: " + results[i].getCodeTypeName())
i += 1

上面 Python 中的示例通过几个 API 调用从图像中读取条形码。 API 能够从 DecodeType 枚举器中指定的不同其他条形码类型读取信息,包括 GS1 代码、代码矩阵、二维码、代码 128、CODABAR 等。通过在 Python 条码阅读器 中使用几行代码,已经开发出来。

在本主题中,我们探讨了在 Python Barcode 扫描仪应用程序中开发的容易程度。如果您想了解有关创建条形码的信息,请参阅有关如何在 Python 中生成条形码 的文章。

 简体中文