2012年3月23日 星期五

Using OpenCV 2.3.1a in Xcode 4

I'm now using Mac OS X to writing my OpenCV project

(install OpenCV in 1 minute, just open terminal and type the three red lines!!)


To build the environment, first we should have OpenCV in our OS

I use homebrew to install OpenCV 2.3.1a and I think it's very easy and fast.

First open your terminal and type
/usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

By doing this, homebrew is now inside your system.

[wp_ad_camp_2]
(homebrew works if you have already installed Xcode.)

then type brew install opencv

OpenCV 2.3.1a is now in your Mac OS X.

But we still have to install one componet -- Python.
Type brew install python
and now we can coding in Xcode 4

To coding in Xcode 4, we have to link our project to OpenCV library.

First, open Xcode and create a new project in Application -> Command Line Tool.
Click Next and choose C++ and set Product Name like wanesbbOpenCV
Click Next and choose where you want to save the project and you will see...
Then choose Project -> wanesbbOpenCV and find Header Search Path

insert three path inside the field
/usr/local/Cellar/opencv/2.3.1a/include
/usr/local/Cellar/opencv/2.3.1a/include/opencv
/usr/local/Cellar/opencv/2.3.1a/include/opencv2
(it's depend on the version homebrew use, so u better check it)

Then, find Library Search Path And insert one path inside the field
/usr/local/Cellar/opencv/2.3.1a/lib

Last, find Other Linker flags And insert one path inside the field
-L/usr/local/Cellar/opencv/2.3.1a/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
(u can check this value by terminal using pkg-config opencv --libs)

Now, you can run with this code

[gist]http://gist.github.com/936194[/gist]

And show the pic you want!

To run it much better, remember to reopen the project so the Xcode can help you with Autocomplete
[wp_ad_camp_1]

1 意見:

Sumit 提到...

Hi,

Thanks a lot for the instructions.

I'm doing exactly the same thing, however I'm getting the following errors (listed below). Any ideas where I could be going wrong? I'm using Xcode 4.3 and installed the opencv 2.3.1a using homebrew.

Thanks,
Sumit


Ld /Users/spchopra/Library/Developer/Xcode/DerivedData/knightrider-hiewnssfcsbagpacwtexsibagzcd/Build/Products/Debug/knightrider normal x86_64
cd /Users/spchopra/research/ml/att/knightrider/src/knightrider
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -L/Users/spchopra/Library/Developer/Xcode/DerivedData/knightrider-hiewnssfcsbagpacwtexsibagzcd/Build/Products/Debug -L/usr/local/Cellar/opencv/2.3.1a/lib -F/Users/spchopra/Library/Developer/Xcode/DerivedData/knightrider-hiewnssfcsbagpacwtexsibagzcd/Build/Products/Debug -filelist /Users/spchopra/Library/Developer/Xcode/DerivedData/knightrider-hiewnssfcsbagpacwtexsibagzcd/Build/Intermediates/knightrider.build/Debug/knightrider.build/Objects-normal/x86_64/knightrider.LinkFileList -mmacosx-version-min=10.7 -L/usr/local/Cellar/opencv/2.3.1a/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -o /Users/spchopra/Library/Developer/Xcode/DerivedData/knightrider-hiewnssfcsbagpacwtexsibagzcd/Build/Products/Debug/knightrider

ld: library not found for -lopencv_core
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ failed with exit code 1

張貼留言