Installing OpenCV in Mac OSx tutorial

By | January 10, 2015

Installing OpenCV in Mac OSx tutorial – OpenCV 2.4.10 on OSx 10.10 Yosemite

Please see the latest blog to install OpenCV 3 on macOS here !

Notes : Consider following suggestions before you start installing OpenCV on your Mac

1. Do not use any “beta” versions – for both OpenCV and XCode (Please Avoid / Use stable versions)

2. If you’re following this tutorial then do not cross check or mess up with other tutorials online

3. Using Macports to install OpenCV – it’s easier and perfect

4. Terminal is the best for entire installation

 

Tutorial :

Step 1 : Check XCode and Mac OSx

Make sure you are using stable version of Mac OSx and XCode. In my case, I’m using Mac OSx 10.10 Yosemite and XCode 6.1.1

Also install Command Line tools for your XCode ! Get it from here!

 

Step 2 : Macports

Using macports to install OpenCV is very perfect I found. You can find a detailed macports installation/updation tutorial here.

1. Open terminal

2. Select XCode Latest version :

sudo xcode-select -s /Applications/XCode.app/Contents/Developer

3. Run command for agreeing the license :

sudo xcodebuild -license

4. Update Macports using :

sudo port -v selfupdate

 

Step 3 : Install cmake

In terminal, run;

sudo port install cmake

 

Step 4 : Download OpenCV

First, download OpenCV latest version on Mac from here.  Do not use any beta version. I am using OpenCV 2.4.10 ! Extract the folder and keep the OpenCV folder at some better place in your mac (Not in downloads)

 

Step 5 : Install

In terminal, navigate to your opencv folder. then run following command :

note: there’s a space between two dots.

 

Screen Shot 2015-01-08 at 7.52.24 pm

now,

now, wait some time till it gets install !

 

Screen Shot 2015-01-08 at 7.51.43 pm

 

Step 6 : Run a demo program in XCode

1. Start New Project

2. Select for OSx and command line app

3. Change following settings

-> In build settings, change architecture to Native

-> Set Search paths as following :

Header search path : /usr/local/include

Library search path : /usr/local/lib

Screen Shot 2015-01-10 at 6.11.53 pm

-> C++ standard Library

Screen Shot 2015-01-10 at 6.14.17 pm

4. Add following libraries in your project (Add files)

libopencv_core.2.4.10.dylib

libopencv_highgui.2.4.10.dylib

 

5. Run this code that draws two circles

 

Installing OpenCV in Mac OSx tutorial

 

 

 

 

 

 

 

  • Aaron Lowndes

    Can you please let me know why the new app created needs to be a command line app? All of the tutorials similar to this state that as well. my App is already half-built (as a Cocoa app, OSX type) and has a lot of processing already done and working with Core Image. I just want to pass bits of images to OpenCV for processing, then pass the info found back to the main program.

    • Aaron Lowndes

      specifically, pass a face rect found with CIDetector to OpenCV, and have OpenCV detect the size of a smile and pass that info/rect back to the main program for drawing. Again this is in OSX, not IOS

      • Yes, even if it’s for the OSx, you can use static OpenCV libraries and use OpenCV functions and get face and smile detected and utilise those values in your Mac app code.

    • Hi Aaron,
      We use command line app to run programs that are using OpenCV library because we deal with dynamic libraries .dylibs ! As you’re working on an Cocoa app, you will need to bind libraries with your app, so I think you will need static libraries .a files.

      • Aaron Lowndes

        Thanks for the clarification!

  • Ara77

    After I typed <> I just can’t reach to 100%.
    At 57%, 65% and 68% I get errors

  • Ara77

    problem soved
    Open CMake.
    Browse Source: openCV folder.
    Browse Build: build Folder.
    Uncheck BUILD_opencv_legacy

  • Matt Black

    hey Harsh. the OpenCV 2.4.10 link is 404. I looked but couldnt find it elsewhere. any workarounds? thanks