Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Python + OpenCV + dlib in Azure Functions

I have created an image processing script in Python (with dlib and OpenCV) - I was wondering how I can bring this functionality to Azure Functions, so that the script can be called via an API. As Python is still in preview for Azure Functions I wanted to know if anybody here has experience with bringing modules to Azure Functions and if it's possible to install OpenCV there?

like image 391
nor0x Avatar asked Oct 30 '16 17:10

nor0x


1 Answers

You can bring your own modules to your Function by uploading them into the a lib folder residing in the same folder as your Function.

However, in the context of OpenCV, it is not a supported scenario at the moment. The default Python version being used in the Azure Function environment is Python 2.7. If you try to execute a Function code using OpenCV for Python 2.7, the error message you will get would be similar to the following,

2016-11-07T20:47:33.151 Function completed (Failure, Id=42fa9d38-05f1-46d4-a8ce-9fbaa24a870d)
2016-11-07T20:47:33.166 Exception while executing function: Functions.ImageProcessor. Microsoft.Azure.WebJobs.Script: ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
  File "D:\home\site\wwwroot\ImageProcessor\run.py", line 17, in <module>
    import cv2
ImportError: numpy.core.multiarray failed to import

The fix for this is to update the numpy version used by Python 2.7, but you will not be able to run the update yourself.

As you have noted, Python language support for Azure Functions is in an experimental stage right now. These issues will be addressed when Python is fully on-boarded as a first-class language.

like image 138
Ling Toh Avatar answered Nov 05 '22 11:11

Ling Toh