Installation - zlacey1234/LearningOpenCV GitHub Wiki

Installing OpenCV on Linux (Computer)

Note: This tutorial assumes using Ubuntu 16.04 with OpenCV

Required Packages

  • GCC 4.4.x or later
  • CMake 2.8.7 or higher
  • Git
  • GTK+2.x or higher, including headers (libgtk2.0-dev)
  • pkg-config
  • Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
  • ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
  • [optional] libtbb2 libtbb-dev
  • [optional] libdc1394 2.x
  • [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
  • [optional] CUDA Toolkit 6.5 or higher
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

Getting OpenCV Source Code

  1. Make a OpenCV Build Directory
cd ~ 
mkdir opencv_build
cd opencv_build
  1. Clone the OpenCV Repository from Github
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
  1. create a temporary build directory within OpenCV Repository, where the generated Makefiles will be placed.
cd ~/opencv_build/opencv
mkdir build
cd build
  1. Configuring. Run cmake cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local .. -DOPENCV_GENERATE_PKGCONFIG=ON
  2. Build. From build directory execute make, it is recommended to do this in several threads make -j7
  3. To install libraries, execute the following command sudo make install

Setup the shared location of the OpenCV Library

  1. Check to see if OpenCV was properly built. Navigate to the path: /usr/local/include. There should be an opencv4 folder which contains the opencv2 folder
  2. Navigate to the path: /usr/local/lib. This should contain the shared libraries (files beginning in lib and usually ending in .so). An example of this should be libopencv_core.so. If these files were properly placed here, then proceed to Step 3. Otherwise, find the location of these files.
  3. Create a file called /etc/ld.so.conf.d/opencv.conf. To do this, navigate to the path: /etc/ld.so.conf.d\
sudo gedit opencv.conf
  1. In the opencv.conf file write:
/usr/local/lib/
  1. Run
sudo ldconfig -v

Installing OpenCV on Linux (Raspberry Pi 4B)

TODO