How I made Open-Cv working with XCode on my mac

After many frustrating attempts I finally made OpenCv works on my mac.

Here I’ll explain how:

1) Install CMake  (http://www.cmake.org/cmake/resources/software.html ) by just flowing the installer assistant

2)Download OpenCv (http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/)

3)Execute the followings instruction in your Terminal (/Applications/Utilities/Terminal)

cd /path to your download folder
tar xvf OpenCV-your version.tar.bz2
cd OpenCV-your version
mkdir build
cd build
cmake -G "Unix Makefiles" ..
make
sudo make install

4) Now under /usr/local/lib you should have some new files beginning with OpenCV

:usr:local:lib

 

 

 

5) Now create a new XCode project

Step1

6) Now your project is create you can add the library we just download under “Build Phases”

Step2

6) Link the binaries by cliking “+” then “Add Other…” . A window pop-up, then strike “/” for me it was “shift-7” (in Switzerland) and type /usr/local/lib . The select opencv core & highgui which are the two most important library to have.

Step3

7) Now you should have the to library on the left bar, you can put the files into a seperate folder to make your project cleaner if you want.

Step4

8) Finally under “Build Settings” search for the “Search Paths” section and modify the entries as shown below.

 

 

 

 

 

42) The last step is to learn OpenCv.

Here is a template I always start with this make the include much easier.

// main.cpp

#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
CvCapture *capture;
IplImage *img;

int key;

capture = cvCreateCameraCapture(CV_CAP_ANY);
cvNamedWindow( "First Code", 1 );

while( key != 'q' )
{

img= cvQueryFrame( capture );
cvShowImage( "First Code", img);
key = cvWaitKey( 10 );

}

cvReleaseCapture( &capture );
cvDestroyWindow( "First code" );

return 0;
}

It just return the input of your webcam 🙂

Good Luck. And catch you next time.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s