python - 如何获得使用 Zbar 在 AWS lambda 中工作的 python 函数?
问题描述
在一些关于如何在 python 中执行此操作的教程之后,我构建了以下 qr 阅读器函数。执行这项工作的主要库是 Zbar(或 PyZbar 或类似的派生类)。我已经在我的计算机上启动并运行了该功能,它似乎工作得很好。
现在我想用它构建一个小型应用程序,并且由于我想将事物分开,我希望 qr 解码器功能能够根据 AWS lambda 的需求工作。这个想法是,有人用他们的应用程序拍摄 QR 码的照片,上传图片(到 S3 存储桶),Lambda 函数对此上传做出反应,读取代码并从 QR 码返回数据。
我一直在做我的研究,我自己是 AWS lambda 的新手,并且已经能够弄清楚如果没有预装在 AWS 上,函数需要与依赖项一起上传。我已经能够按照此视频的说明上传它们。但是,当我对函数进行测试运行时,它会引发错误。
我开始怀疑是否真的可以将 QR 阅读器内置到 Lambda 函数中......对此有任何帮助/指向其他方法来执行此操作/现有服务可以执行此操作吗?
我的功能代码:
def scan_qr(image):
# USAGE
# python barcode_scanner_image.py --image barcode_example.png
# import the necessary packages
from pyzbar import pyzbar
import argparse
import cv2
import pandas as pd
# construct the argument parser and parse the arguments
args=image
# load the input image
image = cv2.imread(args)
# find the barcodes in the image and decode each of the barcodes
barcodes = pyzbar.decode(image)
# loop over the detected barcodes
for barcode in barcodes:
# extract the bounding box location of the barcode and draw the
# bounding box surrounding the barcode on the image
(x, y, w, h) = barcode.rect
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
# the barcode data is a bytes object so if we want to draw it on
# our output image we need to convert it to a string first
barcodeData = barcode.data.decode("utf-8")
barcodeType = barcode.type
# print the barcode type and data to the terminal
your_list = pd.DataFrame(
{'type': [barcodeType],
'url': [barcodeData]
})
your_list = your_list[your_list.type=='QRCODE']
return(your_list)
解决方案
Zbar 具有本机依赖项。新的 Lambda 功能允许您构建自己的 docker 映像。因此,您可以将 zbar 构建到图像中。
推荐阅读
- python - 在另一台计算机上复制 Python 环境
- r - 如何使用 seq() 和 rep() 和 paste() 生成特定向量?
- android - 任务“:amplifyPush”执行失败
- blazor - 如何托管 Blazor 应用程序?
- arrays - 如何读取文本文件并存储在 C 中的数组中
- python - 正确使用 np.where() 输出数据帧而不是元组
- c++ - 谁能解释以下代码的工作原理?
- sql - 如何使用递增的数字更新字符串值
- azure - 在 Azure Synapse 中,是否确实不鼓励创建临时表?
- python - 即使索引看起来正确,Pandas 也会应用返回索引错误