9

I'm trying to install OpenCV on Heroku so my Python web app can use OpenCV. How can I go about doing this?

Thanks!

5 Answers 5

8

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 :

opencv-python-headless

Sign up to request clarification or add additional context in comments.

1 Comment

This was simpler than other answers and solved my problem.
5

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.

3 Comments

Thanks for posting this Diogo. The links posted by @friism did not work for me either, and I will try this and let you know my success at a later point (at this point, it's for an old project that I ended up using Amazon EC2 for instead).
@Diogo I tried using your buildpack, but get this error. Any help much appreciated. 2017-04-19T13:17:39.305177+00:00 heroku[web.1]: Starting process with command python app.py runserver 0.0.0.0:5000 2017-04-19T13:17:42.488675+00:00 app[web.1]: ruby: symbol lookup error: /usr/lib/ruby/1.9.1/x86_64-linux/enc/encdb.so: undefined symbol: rb_enc_set_base 2017-04-19T13:17:42.503774+00:00 app[web.1]: ImportError: No module named site
As of 2018, you can use a buildpack to install apt libs. See stackoverflow.com/a/51004957/660711
3

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.

Comments

1

The following steps should solve the problem of openCV which you are facing -

  1. Add the heroku-buildpack-apt to the BuildPack by pasting - https://github.com/heroku/heroku-buildpack-apt to add buildpack in dasboard. ScreenShot - Adding through Dashboard -> Settings -> Add BuildPacks
  2. Then add the Aptfile in your Github base directory which contains -
libsm6 
libxrender1
libfontconfig1
libice6

Now build and deploy and you are ready to go!

1 Comment

Welcome to Stack Overflow. FYI, if you come across several questions for which you believe the exact same answer will solve all of the questions, you should not post the answer on all of the questions (they probably be deleted either by a moderator or an automated check for duplicate answers). What you should do is consider flagging the posts as duplicate questions.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.