Skip to content

Instantly share code, notes, and snippets.

@AmitThakur
Last active March 13, 2024 05:08
Show Gist options
  • Save AmitThakur/8382707 to your computer and use it in GitHub Desktop.
Save AmitThakur/8382707 to your computer and use it in GitHub Desktop.
How to install OpenCV on LInux (Ubuntu)

opencvp

OpenCV Practice Repository https://github.com/AmitThakur/opencvp.git

Installing OpenCV on Linux platform (Ubuntu)

Credits: [http://www.raben.com/book/export/html/3] [http://karytech.blogspot.in/2012/05/opencv-24-on-ubuntu-1204.html]

  • Install developer environment to build OpenCV source code:
sudo apt-get install build-essential cmake pkg-config
  • Install Image I/O libraries:
sudo apt-get install libjpeg62-dev
sudo apt-get install libtiff4-dev libjasper-dev
  • Install Python development environment:
sudo apt-get install python-dev python-numpy
  • Install Video I/O libraries:
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev

Optional

  • Install Intel TBB for OpenCV parallel coding:
sudo apt-get install libtbb-dev
  • Install GUI backend-GTK or QT:
sudo apt-get install libqt4-dev libgtk2.0-dev

Get OpenCV Source Code:

Get latest version using Git:

cd ~/path/to/working/directory
git clone https://github.com/Itseez/opencv.git

Or get the source package from http://opencv.org/downloads.html, extract and create build directory inside opencv directory: (Replace * with numbers as per requirement)

tar -xvf OpenCV-*.*.*.tar.bz2
cd OpenCV-*.*.*
mkdir build
cd build
  • Now is the time to generate configure OpenCV build using Cmake. Last two dots are for source directory of OpenCV (Parent Directory here):
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local
    -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON
    -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON
    -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
  • Compiling: (add -j3 or -j4 to make compiling faster)
make
  • Install:
sudo make install

Using OpenCV in your project:

  • First using following command to find out the locations of OpenCV files for include path(-l)
pkg-config --cflags opencv

which gives results like this:

-I/usr/local/include/opencv -I/usr/local/include

So include path is: /usr/local/include/opencv

  • Now we find libraries path using following path:
pkg-config --libs opencv

which gives result like this:

/usr/local/lib/libopencv_bioinspired.so /usr/local/lib/libopencv_calib3d.so ...

So Library search path (-L) is: /usr/local/lib

These path can be included in Compiler Settings of IDEs.

Uninstalling:

cd /path/to/OpenCV-*.*.*/build
sudo make uninstall
@LMWafer
Copy link

LMWafer commented Sep 25, 2021

Yep, that's a very useful .md. Thanks !

@f0ti
Copy link

f0ti commented Jun 18, 2022

to find out the locations for opencv4 in the include path do the following:
pkg-config --cflags opencv4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment