Computer Vision, OpenCV, Technology, Uncategorized

How to install OpenCV 3.2.0 with opencv_contrib modules on macOS Sierra or Ubuntu

Hello, everybody!

Let’s build the brand new OpenCV 3.2.0 with the opencv_contrib modules from source! This will work on both macOS Sierra and Ubuntu.

If you are in an Ubuntu system, I strongly suggest you to run the following commands on your command line:

  • 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

If you are in a macOS system, you should have the essentials but just in case you may want to update everything before start, run the following command:

$ brew update

Now, let’s first get the OpenCV 3.2.0. Go to OpenCV github page, and under the Releases tab, select the Source code (zip) from the 3.2.0 version.

Ok, so the next step is where lots of people have problems (I also had at the fist time): you must download the matching version of the opencv_contrib repository. Unfortunately, the one you download out of the master branch is not the one. Just like the OpenCV source files, you must go to the opencv_contrib Releases tab and download the .zip or .tar.gz file for the version 3.2.0. Your download file should be called opencv_contrib-3.2.0.

Great! Go to the directory you downloaded both the opencv-3.2.0 source files and the opencv_contrib-3.2.0 and extract them.

Inside the OpenCV folder, create another folder called build.

$ mkdir build

Change directory to build.

$ cd /build

Then, you will use the cmake to generate the makefiles that will allow you to compiler the entire library. Since we are calling the path to where you downloaded the opencv_contrib-3.2.0 as , you should run the following command.


Then, run:

$ make -j4 

The -j4 is flag that will tell your computer to run the make with four jobs in parallel, which will be faster. Is usually good to place -j. So, if you have 8 cores, you may run $ make -j8.

And to install the libraries, inside of the build folder run the following command:

$ sudo make install 

On the next post, I will teach you how to use CMake to compile and run OpenCV codes. For a video explanation, please head to my YouTube video where I show how to install the OpenCV 3.1.0 on Ubuntu.

I hope you all enjoyed!

I’ll see you on the next post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s