Saturday, February 1, 2014

Tutorial: Configure Xcode for OpenCV programming

In this post I want to show you how to configure Xcode to work with OpenCV if you installed it like I explained here.

Start Xcode

1. When you open Xcode, select "Create a new Xcode project".

2. Under OS X Applications select "Command Line Tool".

3. Give your project a name and select as Type "C++".

4. Select a path where you want to save your project.

Configure Xcode

Before actually writing some code, we have to prepare Xcode so that it can use OpenCV. For this we have to include the header and library files.

As I explained in the install tutorial, OpenCV was installed to /usr/local. The header files are in /usr/local/include and the libraries are located in /usr/local/lib. These paths we have to add to the "Search Paths" in Xcode. To go there, you have to:

1. Select your project file in the project navigator on the left.

2. Now you can access the "Build Settings". In the search box type in "Search Paths" or simply scroll down until you see them.

3. Double click on "Header Search Paths" and add two lines:
    /usr/local/include
    /usr/local/lib

4. Double click on "Library Search Paths" and add this line:
    /usr/local/lib

5. Now we just have to add the *.dylib files from OpenCV. To do this:

  5.1 right click on your project file.

  5.2 Select "Add files to "projectname" ...".

  5.3 Don't select a path. Just hit / to open a line where you can specify a path. Enter /usr/local/lib and hit enter.

  5.4 Select all the *.dylib files you want to add. Just add all of them for now. If you want to you can create a folder and move all the files in there.

Finally it should look like in this screeshot below. With this configuration you are ready to write programs with OpenCV.


Remark:
In case you didn't build opencv yourself and installed it instead via macports, the procedure of configuring Xcode is the same. Just modify the paths. Instead of
/usr/local/lib and /usr/local/include
Macports installs the libraries in
/opt/local/lib and /opt/local/include

Program versions:
OS: Mac OS X 10.9.1
Xcode: 5.0.2
OpenCV: 2.4.8.0

1 comment: