简体   繁体   English

如何在 AWS lambda 上导入 opencv 模块

[英]How do I import the opencv module on AWS lambda

I'm working on the project that requires me to run my code on the AWS cloud, I've tried some tutorial and I successfully used the python numpy module on AWS lambda, even I'm using window OS, following https://serverless.com/blog/serverless-python-packaging/我正在从事需要我在 AWS 云上运行我的代码的项目,我尝试了一些教程并且我成功地在 AWS lambda 上使用了 python numpy 模块,即使我使用的是窗口操作系统,如下https:// serverless.com/blog/serverless-python-packaging/

However, I would like to import the opencv, I installed opencv-python-headless by pip install opencv-python-headless .但是,我想导入 opencv,我通过pip install opencv-python-headless After all, I counldn't complete my development, it was told that the "unzipped size must be smaller than 262144000 bytes", it's true, since I had my .zip file with size more than 300000000 bytes.毕竟,我无法完成我的开发,被告知“解压缩后的大小必须小于 262144000 字节”,这是真的,因为我的 .zip 文件大小超过 300000000 字节。

My question is can I have the more simple opencv for installing, so I can have the package with smaller than the certain amount, I just want few codes about cv2:我的问题是我可以有更简单的opencv来安装,所以我可以有小于一定数量的包,我只想要一些关于cv2的代码:

faceCascade = cv2.CascadeClassifier(cascPath)
image = cv2.imread(imagePath, cv2.IMREAD_GRAYSCALE )

faces = faceCascade.detectMultiScale(
image,
scaleFactor=1.2,
minNeighbors=5,
minSize=(30, 50),
flags = cv2.CASCADE_SCALE_IMAGE
)

for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
......
lastimg = cv2.resize(crop_img, (182, 182))
cv2.imwrite("crop_{}".format(imagePath), lastimg)

OR is there any method to run these code on AWS cloud, (for example, can I upload my opencv module on AWS S3, and download it when running the above python code.或者有什么方法可以在AWS云上运行这些代码,(例如,我可以在AWS S3上上传我的opencv模块,并在运行上面的python代码时下载它。

My question is can I have the more simple opencv for installing, so I can have the package with smaller than the certain amount (...).我的问题是我可以有更简单的 opencv 来安装,所以我可以拥有小于一定数量的包(...)。

In order to acomplish this, you should build opencv yourself.为了实现这一点,您应该自己构建 opencv。

This way you could set the build options and create a version best suited to your needs.通过这种方式,您可以设置构建选项并创建最适合您需求的版本。

Here are the docs with instructions and build options: https://docs.opencv.org/3.4/d7/d9f/tutorial_linux_install.html以下是包含说明和构建选项的文档: https : //docs.opencv.org/3.4/d7/d9f/tutorial_linux_install.html

Take a look at this build example with the same objective as yours: https://github.com/aeddi/aws-lambda-python-opencv/blob/master/build.sh以与您的目标相同的目标查看此构建示例: https : //github.com/aeddi/aws-lambda-python-opencv/blob/master/build.sh


OR is there any method to run these code on AWS cloud, (for example, can I upload my opencv module on AWS S3, and download it when running the above python code.或者有什么方法可以在AWS云上运行这些代码,(例如,我可以在AWS S3上上传我的opencv模块,并在运行上面的python代码时下载它。

Sadly, not that I know of.可悲的是,我不知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM