Jul 27, 2015

Installing OpenCV 3 on Ubuntu 12.04

After spending the morning fighting my way through this, here are some notes for myself and Google to index. Before you get started;

  • Install a slightly newer cmake
sudo add-apt-repository --yes ppa:kalakris/cmake
sudo apt-get update -qq
sudo apt-get install cmake
  • Set up a lightweight development environment (or similar) as per this article
  • Download and install Libav v9
./configure --prefix=/opt/opencv3 --enable-pic --disable-static --enable-shared
cd opencv-3.0.0
rm -rf ./build && mkdir build && cd build
  • Invoke the build like follow
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/opt/opencv3 \
-D PYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON_EXECUTABLE=$(which python) \
-D PYTHON_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D WITH_VTK=OFF -D WITH_CUDA=OFF \
-D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D WITH_FFMPEG=ON -D WITH_1394=OFF \
-D WITH_WEBP=OFF -D ENABLE_SSE42=ON -D ENABLE_SSE41=ON -D ENABLE_SSE42=ON \
-D ENABLE_POPCNT=ON -D ENABLE_AVX=ON -D ENABLE_SSSE3=ON \
-D INSTALL_PYTHON_EXAMPLES=ON -D WITH_GSTREAMER=OFF \
-D WITH_GTK_2_X=ON -D INSTALL_C_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules/ \
..

Some other observations;

  • If the build doesn't succeed you need to remove and recreate the build directory again (as CMake somehow fails to cache the Python configuration).
  • The gtk+-3 gui backend doesn't auto-resize image windows correctly
  • It would probably be easier to move to a newer Ubuntu LTS, or preferably debian stable.