2013年11月4日 星期一

Using OpenCV on Xcode

The install process should be as follow.

1. Install MacPorts through pkg file  
http://www.diigo.com/annotated/99033418ec79c564a75a4c33609c9de2

ps. 若出現 port : command not foundsudo vi /etc/pathsAdd 2 following lines: (先按i開啟編輯模式)
/opt/local/bin
/opt/local/sbin  (輸入  :wq   存檔並離開)
Reboot your terminal

2. Install OpenCV throught 'Terminal' 
sudo port install opencv
3. Add library to your Xcode project which shown as belowBy default OpenCV is installed to /opt/local/ according to MacPorts conventions. The opencv_xxxx utilities are located in /opt/local/bin/, the dynamic libraries in /opt/local/lib/ and the header files in /opt/local/include/opencv/.

也就是說因為XCODE他的預設路徑在var底下,你可以把opt底下的東西拷貝到var底下,或者像我一樣到Xcode的 project檔案Build TAB底下去設定header 跟 libraries 的路徑。
OpenCV所需要的library加入用Xcode
開啓一個new command project
點選上方工具列 Project -> New Group 來創立一個新的Group 
在這裡我們稱他OpenCV Frameworks
左方輕點選剛剛創立出來的OpenCV Frameworks
點選上方工具列 Project -> Add to Project按下"/" 輸入/opt/local/lib 選擇下面三個檔案加入
  • libopencv_core.2.2.0.dylib
  • libopencv_highgui.2.2.0.dylib
  • libopencv_imgproc.2.2.0.dylib
4. Use #include <cv.h> #include <highgui.h> in the top of your program.