by razola



OpenCV 3 with extra modules for Heroku Rails apps

# 1. Install Numpy via Conda
heroku buildpacks:add --index 2
echo "numpy=1.11.2" > "conda-requirements.txt"
git push heroku master

# 2. Start a one-off dyno with a shell prompt
heroku run bash

# 3. Download and install CMake
tar zxf cmake-3.7.1-Linux-x86_64.tar.gz && rm cmake-3.7.1-Linux-x86_64.tar.gz
mkdir -p .heroku/cmake
mv cmake-3.7.1-Linux-x86_64/bin .heroku/cmake
mv cmake-3.7.1-Linux-x86_64/share .heroku/cmake

# 4. Download and install OpenCV 3 with extra modules (CMake for some reason couldn't find the PYTHON2_INCLUDE_DIR and PYTHON2_LIBRARY dirs)
unzip && rm
unzip && rm
cd opencv-3.2.0
../.heroku/cmake/bin/cmake -DPYTHON2_INCLUDE_DIR=/app/.heroku/miniconda/include/python2.7 -DPYTHON2_LIBRARY=/usr/lib/x86_64-linux-gnu/ -DCMAKE_BUILD_TYPE=Release -DOPENCV_EXTRA_MODULES_PATH=/app/opencv_contrib-3.2.0/modules -DCMAKE_INSTALL_PREFIX=/app/.heroku/opencv .
make && make install

# 5. Compress binaries and manually upload it to your S3 bucket via (don't forget to make the file public)
cd ..
tar zcf opencv-with-contrib.env.tgz .heroku/opencv .heroku/cmake
curl --upload-file opencv-with-contrib.env.tgz

# 6. Add buildpack, the URL to the binaries and deploy
heroku buildpacks:add --index 3
heroku config:set OPEN_CV_S3_URL=
git push heroku master

Note that before "import cv2" you'll need to do:

import sys
import cv2