本主题介绍了使用 Python 扫描 QR Code 的过程。它涵盖了算法,并包含创建 Python 中的二维码扫描器的示例代码。此外,您不需要图像处理软件即可从任何图片中读取二维码。
使用 Python 扫描二维码的步骤
- 安装 Aspose.BarCode for Python via .NET 来扫描二维码
- 创建 BarCodeReader 类的对象来加载输入图像
- 使用 DecodeType 指定解码类型以进行识别
- 读取二维码并打印结果
上述步骤概述了使用 Python 读取二维码的工作流程。该过程从新版本部分配置 API 开始。接下来,加载源图像并指定解码类型。最后,读取二维码并打印结果。
使用 Python 从图像扫描二维码的代码
import aspose.barcode | |
import aspose.barcode as barcode | |
from aspose.barcode import * | |
from aspose.barcode import barcoderecognition | |
path = "C://SampleFiles//" | |
license = aspose.barcode.License() | |
license.set_license(path + "License.lic") | |
# Instantiate the BarCodeReader | |
BarcodeReader = barcoderecognition.BarCodeReader("qr-code.png" , barcoderecognition.DecodeType.QR) | |
# Read the QR code | |
results = BarcodeReader.read_bar_codes() | |
for x in results: | |
print(x.code_text) | |
print(x.code_type_name) |
此代码片段旨在使用 Python 创建 QR 读取器。首先,创建一个 BarCodeReader 类对象,同时指定源二维码或条形码的 DecodeType。最后,将识别结果打印为二维码文本及其类型。
在本教程中,您已学会使用 Python 扫描二维码。如果您想生成 EAN13 条形码,请参阅 使用 Python 生成 EAN13 条形码 上的文章。