A quick guide OpenCV: Setup & Installation

Part 1: Installing OpenCV on MacBook

Arjit Sharma
4 min readOct 19, 2019

I was introduced to this amazing library by one of my colleague and within few days I realised what benefits and learning it brings on the table.
I am writing this tutorial for all the image processing enthusiast who want to start learning OpenCV by their own and want to convey through this medium that this is a very simple and interesting stream to work with.

What is OpenCV:

OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library that helps in building image processing programs. For example: Changing background colour, identifying face, blur a face in an image and many more such things.
Okay enough of theory, let’s start the installation:
Just to keep all aware, I am installing and Configuring openCV on MacBook with macOS Mojave ver. 10.14.5

STEP 1:

Download the latest version of OpenCV from their Website. That was easy isn’t it ? For me the version was — opencv-4.1.1
After you download it make sure you place it in location where you want it to be. Because once openCV is configure and if you change the location, it will loose all the link of previous project.

STEP 2:

Download MacPort, if you not have it already. Make sure you download the correct package for the correct operating system you have on MacBook. Once the package is downloaded, install Macports. Check if it correct install by using following command:

port command run

STEP 3:

Congratulations… reaching here. You guys really have a spark to go-ahead. Now the fun begins:

  1. Open Terminal and cd (change directory) to your openCV folder location. So for me it was cd to opencv-4.1.1
  2. Inside your openCV folder (opencv-4.1.1) create a folder named build and the cd in build.
compiling step 1 openCV

STEP 4:

Now we have to build openCV so that we can use it in XCode.

compiling step 2 openCV
cmake -G "Unix Makefiles" ..

CMake produce Ninja build files, or KDEvelop or Xcode projects, or Visual Studio solutions based on enviornment where you run, effectively create the foundation to work upon.
CMake does a two-step build: it generates a low-level build script in ninja or make or many other generators, and then you run it

-G <generator-name>: Specify a build system generator.

CMake may support multiple native build systems on certain platforms. A generator is responsible for generating a particular build system. Possible generator names are specified in the Generators section.

For more information CMake, please read: https://stackoverflow.com/questions/26007566/how-is-cmake-used

Once cmake completes successfully and creating the desisred files, we build them using “make” command.

make -j8

This will actually build the files and will create the library files that we ca use and reference inside our XCode Programs.
And the final step is:

sudo make install

When you do “make install”, the make program takes the binaries from the previous step and copies them into some appropriate locations so that they can be accessed.

Wooaaahhh…!!! All is done.
Now if you go to your build folder, you can see a lot of files are created.

Within build folder if you see lib folder, you can see a lot of “.dylib” files which are frameworks. We will use these files in our XCode and will start openCV programming.

If you were able to use the tutorial and set-up your openCV environment, kindly et me know with a clap or two :-).
And don’t forget to go through part 2 of this series of a step by step tutorial ( with git code repository) on to use openCV to read and write a video file, Blur region of intrest and do a face blur, all using C++, OpenCV and Xcode.

--

--