Manuel Ignacio López Quintero

Do you like this article? Share it with this link. Thanks!

Install OpenCV on Ubuntu or Debian

Install OpenCV on Ubuntu or Debian is a bit long but very easy. You can install OpenCV from the Ubuntu or Debian repository or from the official site.

Option 1. Install OpenCV from the Ubuntu or Debian repository

You can install OpenCV from the Ubuntu or Debian repository: sudo apt-get install libopencv-dev python3-opencv. However, you will probably not have installed the latest version of OpenCV and you may miss some features.

Option 2. Install OpenCV from the official site

To install the latest version of OpenCV be sure that you have removed the library from the repository with sudo apt-get autoremove libopencv-dev python-opencv and follow the steps below.

2.1. Run an installation script

The most simple and elegant way to install a library is running an installation script.

Download the installation script install-opencv.sh, open your terminal and execute:

bash install-opencv.sh

Type your sudo password and you will have installed OpenCV. This operation may take a long time due to the packages to be installed and the compilation process.

2.2. Execute some OpenCV examples

Go to your OpenCV directory and execute a C++ example:

cd build/bin

./example_cpp_edge ../../samples/data/fruits.jpg

Now, go to your OpenCV directory and execute a Python example:

cd samples/python

python3 video.py

Finally, go to your OpenCV directory and execute a Java example:

cd samples/java/ant

ant -DocvJarDir=../../../build/bin -DocvLibDir=../../../build/lib

2.3. Compile a demonstration

Download the files demo.cpp and CMakeLists.txt and put them into a folder. Now, open your terminal, go to the folder and execute:

mkdir build && cd build && cmake .. && make

Finally, run the demo: ./demo.

And that's it! You have installed OpenCV, run some examples, and compiled OpenCV code!

Do you like this article? Share it with this link. Thanks!