Saturday, March 14, 2015

Configure Xcode 6.0 to develop OpenCV

As a newbie to both Xcode and OpenCV, it is really painful to make them work together smoothly. Here I list the way I figured out and hope it could help you a little bit.

Since all the following instructions come from other online resources, which I will make a reference as much as I can, MOST credits go to them.

We assume that you have installed MacPorts and CMake, otherwise, please search how to install them in Google and follow one instruction to install them.

1. Install OpenCV
   a) Choose the right version. The latest version is 3.0, which is too new for most online samples. I choose 2.4, which is the default version MacPorts can find.
  b) install OpenCV by MacPorts
      $sudo port list opencv     #check opencv version first
      $sudo port install opencv

  Many blogs like [1] and [2] list a very complex steps to configure OpenCV,  most of which I do not know why. The easiest way is just let Macport handle all of them.


2. Configure Xcode
   a) Find the directory where OpenCV has been installed.
     My open CV is installed in /opt/local/include/opencv, /opt/local/include/opencv2, /opt/local/lib/. It could also be installed in /usr/local/include and /usr/local/lib. Find the directory of opencv and opencv2 and you find the OpenCV.
 
   b) Create a command-line project in Xcode 6.0.
   c) Click the root directory (project), and on the right of the project, you can find the configuration of the project. Click "all" tab which will show you all the configuration items.

   d) Scroll down to find the item "Search Paths"
     (i) Click "Header Search Paths",  add "/opt/local/include".
     (ii) Click "Library Search Paths", add "/opt/local/lib"

  e) Scroll up to find the item "Linking"
     Click "Other Linker Flags ", add the following.
  "-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab"


In [3], they have a very detailed instruction, however, their OpenCV is 3.0. There linker flags have to be removed, which are "-lopencv_imgcodecs", "-lopencv_shape" and "-lopencv_videoio".

Sometimes, you might have to add "-lopencv_legacy" to include some obsolete lib of OpenCV.

Find some samples and have fun!

[1]https://sites.google.com/site/learningopencv1/installing-opencv
[2] http://blogs.wcode.org/2014/10/howto-install-build-and-use-opencv-macosx-10-10/
[3]http://blogs.wcode.org/2014/11/howto-setup-xcode-6-1-to-work-with-opencv-libraries/

No comments:

Post a Comment