OpenCV (Open Source Computer Vision Library) is in our opinion the coolest open-source machine learning software library out there. It's a fun way to get your feet wet in the new and exciting world of machine learning. We'll be adding tutorials for integrating OpenCV into your QT 5 projects. But today we'll show you how to compile OpenCV from source on macOS Mojave using CMake. If you're not familiar with OpenCV, have a look at https://opencv.org/.
So let's get started.
First, we'll head over to https://cmake.org/download/ and grab the .dmg file for Mac OS X 10.7 or later. Make sure you download and install it on your computer before proceeding forward. There's nothing special about the CMake installation that needs to be taken note of.
Now let's download OpenCV from https://opencv.org/releases/. OpenCV maintains its official and stable releases on this page. At the time of this writing, the most current version is OpenCV – 4.1.1.
So we'll click the link labeled iOS pack in the OpenCV – 4.1.1 section. This will download the OpenCV source as a zip file to a folder of your choice, extract it, and make a note of the extracted path since we'll use it in a few moments.
Next, we'll run the CMake Application we downloaded and installed earlier. Let's take a look at that.
So we'll fill in the "Where is the source code" and "Where to build the binaries" with the folder we extracted the OpenCV source and a folder we'll create right next to it called "OpenCV" respectively.
Then hit the Configure button. This will start the configure process. This will take a few seconds.
Next, we'll select the generator. we'll choose "Unix Makefiles" and click finish.
You'll see a short process in CMake, and when it's finished, you'll be able to set various parameters to configure your OpenCV build. There are lots of parameters to potentially configure. Make sure you check the checkbox next to the BUILD_opencv_world option. This will allow building all OpenCV modules into a single library.
If you changed any configuration options, you'll need to click on the Configure button again after changing the build parameters. Wait for the reconfiguration to finish and finally click on the Generate button. This will make your OpenCV build ready to compile.
Now we'll switch over to a command prompt and cd to the directory we specified in CMake as the "Where to build the binaries" folder. Then we'll begin the make process.
That may take a while. But when it's done, we'll install it.
sudo make install
Once that completes, it'll describe the locations of built assets. And you'll be ready to take the next step in your OpenCV projects.