How to install and create OpenCV project on Mac OSX with XCode

Installing OpenCV on Mac OSX has always been a tough issue for me and for this reason that I start to write this post based on my experience.

In this post, I will guide you through installing from package. To start with you may download latest or stable version of opencv from here and choose OpenCV for Linux/Mac. Besides, you also need to install CMake prior to installing OpenCV package. For instruction on how to install CMake on Mac OSX, you may find here.

You can then follow these steps:

1. Extract downloaded OpenCV package

2. Start terminal, navigate to the extracted package, then use the following commands:

mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

    If you are on Mavericks, you may need to disable QUICK TIME by adding “-D WITH_QUICKTIME=OFF” as below:

mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_QUICKTIME=OFF ..

   Then, you can continue with the following commands (Still in Terminal):

make
sudo make install

When you are done with these, you can now start testing by creating a command line tool project in xcode using C++ as below:   

1) Create a new project

File> New..> Project> Command Line Tools > add in a product name and choose Type as “C++”

2) Click on the Project Name on the panel on the left. Project settings will show up on the right hand side. Choose the “Build Settings” tab. Between “BASIC” and “ALL”, choose “ALL”. Search for “HEADER_SEARCH_PATHS” then add “/usr/local/include”.

3) Now, search for “LIBRARY_SEARCH_PATHS” and as shown below, add “/usr/local/lib” to it.

4) Next, right click on the project and choose “Add Files To ProjectName”. On a new pop up dialog go to your installed OpenCV folder (i.e. release folder in the extracted opencv directory) by typing “/” followed by directory, then go to lib folder, select “libopencv_core.dylib” and “libopencv_highgui.dylib” to add (You may add other libraries as needed by your code). You are now ready to test by including header files (#include <opencv2/opencv.hpp>), write some code, and run.

 

DONE! Hope you enjoy and find this post useful!

 

 

 

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment