Luckily Ubuntu has support for getting the build dependencies for a package
directly via apt-get
:
sudo apt-get build-dep opencv
In addition, we'll need a more modern CMake:
sudo add-apt-repository ppa:george-edison55/cmake-3.x
sudo apt-get update
sudo apt-get install cmake
Create somewhere to install OpenCV:
mkdir -p $HOME/opt/opencv
cd $HOME/opt/opencv
cURL is our friend. Use the -L
option to process redirects.
curl -L https://github.com/Itseez/opencv/archive/3.0.0.tar.gz | tar xvz
curl -L https://github.com/Itseez/opencv_contrib/archive/3.0.0.tar.gz | tar xvz
cd opencv-3.0.0
mkdir release; cd release
ccmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/opt/opencv/ \
OPENCV_EXTRA_MODULES_PATH=$HOME/opt/opencv/opencv_contrib-3.0.0/modules ..
Set python include dirs manually (both INCLUDE_DIRS and INCLUDE_DIRS2) and set
library. Paths will be of form $HOME/.pyenv/versions/X.Y.Z/include/pythonX.Y
and $HOME/.pyenv/versions/X.Y.Z/lib/libpythonX.Y.so
. For Python 3, the
pythonX.Y
part may be pythonX.Ym
.
make -j8 all install
Add an environment setup script at ~/opt/opencv/vars.sh
cat >$HOME/opt/opencv/vars.sh <<EOI
# source this file to set up environment
export OPENCV_PREFIX=$HOME/opt/opencv/
export PATH=$OPENCV_PREFIX/bin:$PATH
export LD_LIBRARY_PATH=$OPENCV_PREFIX/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$OPENCV_PREFIX/lib/python3.4/site-packages:$OPENCV_PREFIX/lib/python2.7/site-packages
EOI
source $HOME/opt/opencv/vars.sh
python -c 'import cv2'
python2 -c 'import cv2'
Excuse my lack of knowledge, but where should I set those INCLUDE_DIRS on?