Building OpenCV on MacOS

Preparation

These installation instructions are taken from: https://blogs.wcode.org/2014/10/howto-install-build-and-use-opencv-macosx-10-10/

Download the sources from https://opencv.org/releases/

Extract the zip to /Users/bischowg/Downloads/opencv-4.1.2

Create two new folders inside of the openCV directory, one called StaticLibs and the other SharedLibs.

Build the Static Libraries

Open cmake-gui (type cmake-gui into the console)

Click Browse Source and navigate to your openCV folder.

Click Browse Build and navigate to your StaticLib Folder.

Click the configure button.

You will be asked how you would like to generate the files.

Choose Unix-Makefile from the Drop Down menu and Click OK.

CMake will perform some tests and return a set of red boxes appear in the CMake Window.

You will need to uncheck and add to the following options.

Uncheck BUILD_SHARED_LIBS

Uncheck BUILD_TESTS

Add an SDK path to CMAKE_OSX_SYSROOT,
it will look something like this “/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk”.
—> Option on my system: /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk

Add x86_64 to CMAKE_OSX_ARCHITECTURES, this tells it to compile against the current system

Uncheck WITH_1394

Uncheck WITH_FFMPEG

Click Configure again, then Click Generate.

When the application has finished generating, Open Terminal and type the following commands.

– cd <path/to/your/opencv/staticlibs/folder/>
– make (This will take awhile)
– sudo make install

Enter your password.
This will install the static libraries on your computer.

Build the Shared Libraries

Open cmake-gui (type cmake-gui into the console)

Click Browse Source and navigate to your openCV folder.

Click Browse Build and navigate to your SharedLib Folder.

Click the configure button.

You will be asked how you would like to generate the files.

Choose Unix-Makefile from the Drop Down menu and Click OK.

CMake will perform some tests and return a set of red boxes appear in the CMake Window.

You will need to uncheck and add to the following options.

Check BUILD_SHARED_LIBS

Uncheck BUILD_TESTS

Add an SDK path to CMAKE_OSX_SYSROOT, it will look something like this
“/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk”.
—> Option on my system: /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk

Add x86_64 to CMAKE_OSX_ARCHITECTURES, this tells it to compile against the current system

Uncheck WITH_1394

Uncheck WITH_FFMPEG

Click Configure again, then Click Generate.

When the application has finished generating, Open Terminal.

– cd <path/to/your/opencv/SharedLibs/folder/>
– make (This will take awhile)
– sudo make install

Enter your password.
This will install the shared libraries on your computer.

Problem During Building the Example Application
OpenCV 4.x+ requires enabled C++11 support

Into the CMakeLists.txt add:

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Then call

cmake .
make

Leave a Reply