How to Install OpenCV in Ubuntu 18.04 LTS for C / C++ (Linux)

In this post we will see How to Install OpenCV in Ubuntu for C/C++
OpenCV is an image processing library created by Intel and later supported by Willow Garage and now maintained by Itseez. OpenCV means Intel® Open Source Computer Vision Library. It is a collection of C functions and a few C++ classes that implement some popular Image Processing and Computer Vision algorithms. OpenCV is Available on Mac, Windows, Linux (Terminal environment).

Step 1 – Updating Ubuntu

Step 2 – Install dependencies

Step 3 –  Get OpenCV

Step 4 – build and install OpenCV

Now to check if OpenCV is installed on a machine, run the following commands

We will get the opencv version installed
in this case it’s 3.2.x

Online Course – Machine Learning A-Z: Hands-On Python & R In Data Science Learn to create Machine Learning Algorithms in Python and R from two Data Science experts. Code templates included.

Create a C++ program

Follow the commands

The above command will create a folder called cpp_test and create a main.cpp file inside it
Now place any .jpeg image inside the cpp_test folder.
So Now your cpp_test folder will contain two files as follows
├── sample.jpeg
└── main.cpp

Now open the main.cpp and add the following code

Now compile your code with the following command

Now run the C++ program with the following command

press ESC to exit

Video instruction – How to Install OpenCV in Ubuntu 18.04 LTS for C / C++

Partner Sites

  • Parth

    How to install openCV for c++ on ubuntu 17.10? Kindly guide with some specific tutorial. Thank you for support in advance.

  • Roinoss

    (was bug in make -j4, but i lost connection to internet, so use cmake second time helps)

  • Rider

    opencv installation is really a mess, should be more modular instead of having to hope opencv & contrib have not diverged & are still compatible when it comes to compilation