Getting Started With XCode And OpenCV On Mountain Lion
Ever tried getting OpenCV running in Mac OS X 10.8 (Mountain Lion)?
Plowing through all the documentation and guides can be a pretty daunting task (well, at least they exist). These simple steps will get you up and running with OpenCV 2.4.2 in XCode 4.5:
First compile, build, and install OpenCV from sources:
- Install Homebrew. Open Terminal, and run this command
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
- Run
brew install
with all of {svn, cmake, ffmpeg, libjpeg, libpng } - Get the latest sources for OpenCV (currently OpenCV 2.4.2) here
- Unpack somewhere and cd into the folder in Terminal
- Run
cmake .
- Run
make && make install
Next step is to create an XCode project that uses OpenCV. This is as simple as creating a new C/C++ project and specifying search path for the OpenCV headers and libraries:
- Open XCode and choose
File > New > Project > Command Line Tool
- For the target select
Build Settings
- For Header Search Paths, specify
/usr/local/include
- For Library Search Paths, specify
/usr/local/lib
In main.cpp, add something like this to test it out:
#include <opencv2/opencv.hpp>
int main(int argc, char *argv[])
{
IplImage *img = cvCreateImage( cvSize(100,200), IPL_DEPTH_8U, 3);
cvNamedWindow("Hello World!", CV_WINDOW_AUTOSIZE);
cvShowImage("Hello World!", img);
cvWaitKey(0);
cvDestroyWindow("Hello World!");
cvReleaseImage(&img);
return 0;
}
An alternative method is to install OpenCV with Homebrew, brew install opencv
(not tested), but the dependencies requires amongst other things a fortran compiler, which I didn't want on my system, so I took the slightly more elaborate approach of manually installing dependencies and building OpenCV from source.
Edit:
See also this guide.
blog comments powered by Disqus