How to Install OpenCV in Ubuntu 16.04 LTS for C / C++






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

Online computer science courses to jumpstart your future.

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

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 16.04 LTS for C / C++


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Stuff I use to make videos

Windows notebook – http://amzn.to/2zcXPyF

Apple MacBook Pro – http://amzn.to/2BTJBZ7

Desktop - http://amzn.to/2zct252

Microphone – http://amzn.to/2zcYbW1

notebook mouse – http://amzn.to/2BVs4Q3

Screen Recording Software – Camtasia


  • Raul Alexander

    Package opencv was not found in the pkg-config search path.
    Perhaps you should add the directory containing `opencv.pc’
    to the PKG_CONFIG_PATH environment variable
    No package ‘opencv’ found

  • Raul Alexander

    Package opencv was not found in the pkg-config search path.
    Perhaps you should add the directory containing `opencv.pc’
    to the PKG_CONFIG_PATH environment variable
    No package ‘opencv’ found https://uploads.disquscdn.com/images/e079f0ae50f33017e24db8d8690d3d29ce58a8b2fb44994835f2df22ec0a1306.png

  • nipunasudha

    Thank you, this really helped!

  • Prashant Singh

    Thanks. Can you also show how to use opencv in python using a simple example.
    Does this build also work for use in python.

  • Prashant Singh

    I followed the procedure above. For c++ it’s running fine but for python its throwing error.
    What mistake I am doing. Please solve this.
    https://uploads.disquscdn.com/images/10592378160c3560490f804150b29de092d1c4e3921549418d4d5803e7690724.png

  • Thanks for sharing~ It success on my computer.

  • Chinmesh Manjrekar

    In step 4, 5th command onwards, the current working directory is /opt/opencv/releases, and not /opt/opencv

    Its missleading, please correct it.

    • Yasmine Sidhom

      thanks. that was really helpful

  • Amel

    My Installation was successful but now I have a big Problem, my Computer isn´t working anymore.
    When I´m starting the login comes up on my Ubuntu 16.04, then I type the right Datas.
    It shows me then only quick an Blackscreen with an error message(/dev/nvme0n1p2: clean, 359022/60407808 files, 9919453/241604864 blocks) and then it goes back to the login.
    I think something with the screen resolution is wrong. Here I have another error messages:

    X Error of failed request: BadWindow (invalid Window parameter)
    Major opcode of failed request: 155 (NV-GLX)
    Minor opcode of failed request: 4 ()
    Resource id in failed request: 0x1400003
    Serial number of failed request: 40
    Current serial number in output stream: 40
    gnome-session-check-accelerated: Helper exited with code 256
    gnome-session-binary[25119]: CRITICAL: We failed, but the fail whale is dead. Sorry….
    CRITICAL: We failed, but the fail whale is dead. Sorry….

    Hopefully can someone help me with my Problem.