I'm trying to install OpenCV on Heroku so my Python web app can use OpenCV. How can I go about doing this?
Thanks!
Its for the fellow googlers who might have been facing the same issue.
Just simply change opencv-python
in your requirements.txt to opencv-python-headless
.
opencv-python-headless is an opencv build that has no gpu support. The file libsm.so (P.S dont remember the name correctly) that is giving the error is for GPU support.
For reference :
Links posted by friism didin't work for me, so I created a custom buildpack that should be more than enough for the situation you described.
You can find the buildpack here.
this question has also come up on the Heroku forums. It looks like there are a couple buildpacks you could look into:
Here's how to use a custom buildpack.
The following steps should solve the problem of openCV which you are facing -
libsm6
libxrender1
libfontconfig1
libice6
Now build and deploy and you are ready to go!
it looks like I am late to this thread but here's my solution that worked for me. I needed to demo this API that makes use of OpenCV with Django DRF.
I tried all the solutions that consisted of adding .buildpacks and Aptfiles but none worked for me.
I ended up removing the .buildpacks
file and Aptfile
and added opencv-python-headless
in the requirements.txt file as a replacement to opencv-python
Just doing that got the API working on python-3.8.0 runtime. The libgl1 and such dependencies are for the GUI and GPU centric version that comes with opencv-python
. So you can get away with opencv-python-headless
or opencv-contrib-python-headless
. The only buildpack you need is the heroku/python
buildpack.
For more details, check options 3 and 4 here!
I have a GitHub repo for the same if you want to check it out!
NOTE: You can not use methods like cv2.imshow()
with headless. You wouldn't be meaning to anyway but just a warning.