We use OpenCV for real-time computer vision. Official download page: link
sudo apt install libopencv-dev
Adapted from this post.
-
Upgrade any pre-installed packages:
$ sudo apt update $ sudo apt upgrade
-
Install developer tools used to compile OpenCV 3.0:
$ sudo apt install build-essential cmake git pkg-config
-
Install libraries and packages used to read various image and video formats from disk:
$ sudo apt install libjpeg8-dev libtiff-dev libjasper-dev libpng12-dev $ sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
-
Install GTK so we can use OpenCV’s GUI features:
$ sudo apt install libgtk2.0-dev
-
Install packages that are used to optimize various functions inside OpenCV, such as matrix operations:
$ sudo apt install libatlas-base-dev gfortran
-
Install the Python 3.4+ headers and development files:
$ sudo apt install python3.4-dev
-
$ sudo -H pip install numpy
-
Download OpenCV main repo
$ mkdir -p repos $ cd repos $ git clone https://github.com/Itseez/opencv.git $ cd opencv $ git checkout 3.0.0
-
Download OpenCV contrib repo
$ cd ..
$ git clone https://github.com/Itseez/opencv_contrib.git
$ cd opencv_contrib
$ git checkout 3.0.0
- Configure OpenCV main repo
$ cd ../opencv
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
The last step can also be done by hand using ccmake
.
- Compile and install
(This will probably take a long time, use the
-j
flag to speed up things using multithreaded compilation)
make -j$(nproc) # compile
sudo make install; sudo ldconfig; cd # install and go home
OpenCV 3 has no method to load the SVM unless the specific commit where this was fixed is used (see this and this for related info).
To install OpenCV 3 with support for SVM loading, follow the previous steps, executing the following commands after step 10:
$ cd ../opencv
$ git checkout 37cbcf024c2b4160648299887a7c28d7cf28b1d3
$ cd ../opencv_contrib
$ git checkout 5409d5ad560523c85c6796cc5a009347072d883c
Then, continue with the previous guide, executing steps 11 and 12.
To install OpenCV 3 with Python 3 support and CUDA 8 support (but no NVIDIA driver installed), follow the steps 1-9 of Install OpenCV 3 (With contrib and Python 3 support). Then, perform these steps:
-
Patch the
3.0.0
branch to fix the issue with removedGraphCut
in CUDA 8$ git format-patch -1 10896129b39655e19e4e7c529153cb5c2191a1db $ git am < 0001-GraphCut-deprecated-in-CUDA-7.5-and-removed-in-8.0.patch
-
Configure OpenCV main repo with CUDA and
libcuda.so
path$ mkdir build $ cd build $ cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=ON \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D BUILD_EXAMPLES=ON \ -D WITH_CUDA=ON \ -D BUILD_CUDA_STUBS=ON \ -D CMAKE_LIBRARY_PATH=/usr/local/cuda/lib64/stubs..
The last step can also be done by hand using
ccmake
. -
Compile and install (This will probably take a long time, use the
-j
flag to speed up things using multithreaded compilation)
make -j$(nproc) # compile
sudo make install; sudo ldconfig; cd # install and go home