https://github.com/horihiro/azure-functions-python-opencv-example
Example for using OpenCV in Python 🐍 on Azure Functions <⚡> consumption plan
https://github.com/horihiro/azure-functions-python-opencv-example
azure-functions opencv python
Last synced: about 1 year ago
JSON representation
Example for using OpenCV in Python 🐍 on Azure Functions <⚡> consumption plan
- Host: GitHub
- URL: https://github.com/horihiro/azure-functions-python-opencv-example
- Owner: horihiro
- Created: 2019-10-10T11:57:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-04T22:50:31.000Z (over 6 years ago)
- Last Synced: 2025-04-13T04:07:06.973Z (about 1 year ago)
- Topics: azure-functions, opencv, python
- Language: Python
- Homepage:
- Size: 93.8 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# azure-functions-python-opencv-example
This is **unofficial** sample project of Azure Functions for python with OpenCV
1. Install and run docker daemon
1. Clone this repository and open this by VScode with Azure Functions extension.
1. Edit `HttpTrigger/__init__.py` if you want
1. Deploy to your Function App (Linux and Consumption plan) using Azure Functions extensions.

or

This step includes the process which downloads the libraies to `./lib` (see [this](./utils/))
**Note:**
If you want to deploy it with `--build-native` option, please try to execute `functions-core-tools` directly after executing `./utils/retrieve_so.sh` or `.\utils\retrieve_so.bat`.
1. Before merging this [PR](https://github.com/Azure/azure-functions-docker/pull/170) and publishing the container image,
confirm your code if the libraries are loaded before importing like the following.
```py
# In order to use `import cv2`, necessary libraries need to be loaded by following code before the importing.
import ctypes
exlibpath = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/lib/'
# exlibpath = '/home/site/wwwroot/lib/'
ctypes.CDLL(exlibpath + 'libglib-2.0.so.0')
ctypes.CDLL(exlibpath + 'libgthread-2.0.so.0')
import cv2
```
After merging the PR, you will not need above code, just setting the path including the SO libraries (i.e. `/home/site/wwwroot/lib` ) to App Setting `LD_LIBRARY_PATH`.

The http trigger function can comvert image, which is specified by `image_url` query parameter, to grayscale image using `cv2.imread`, `cv2.cvtColor` and `cv2.imwrite`
|Input|Output|
| - | -|
|||