OSX10.6にopencv2.2をインストール

opencv install memo

macにインストール
まずはここを参照して,macportsからopencv2.2をいれる.
http://playwithopencv.blogspot.com/2010/05/macosxopencv.html

$ sudo port selfupdate
$ sudo port install opencv

インストールのために小一時間放置.



サンプルコードを拝借
http://hirokikana.blogspot.com/2009/08/macopencv.html

コンパイル
gcc -L/opt/local/lib/ -lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_video -I/opt/local/include/opencv/ opencv_test.c -o opencv_test

インクルードパスは,/opt/local
ライブラリパスは"libopencv_~~.dylib"となっているファイルのopencv_から拡張子までをとりあえず全て指定.
ヘッダーは/opt/local/include に格納されいる.

ヘッダーの指定が悪かったのか,以下のようなエラーがでた.
(opencv_testはサンプルプログラム名)

In file included from opencv_test.c:1:
/opt/local/include/opencv/cv.h:63:33: error: opencv2/core/core_c.h: No such file or directory
/opt/local/include/opencv/cv.h:64:33: error: opencv2/core/core.hpp: No such file or directory
/opt/local/include/opencv/cv.h:65:39: error: opencv2/imgproc/imgproc_c.h: No such file or directory
/opt/local/include/opencv/cv.h:66:39: error: opencv2/imgproc/imgproc.hpp: No such file or directory
/opt/local/include/opencv/cv.h:67:38: error: opencv2/video/tracking.hpp: No such file or directory
/opt/local/include/opencv/cv.h:68:45: error: opencv2/features2d/features2d.hpp: No such file or directory
/opt/local/include/opencv/cv.h:69:35: error: opencv2/flann/flann.hpp: No such file or directory
/opt/local/include/opencv/cv.h:70:39: error: opencv2/calib3d/calib3d.hpp: No such file or directory
/opt/local/include/opencv/cv.h:71:43: error: opencv2/objdetect/objdetect.hpp: No such file or directory
/opt/local/include/opencv/cv.h:72:37: error: opencv2/legacy/compat.hpp: No such file or directory
In file included from opencv_test.c:2:
/opt/local/include/opencv/highgui.h:47:39: error: opencv2/highgui/highgui_c.h: No such file or directory
/opt/local/include/opencv/highgui.h:48:39: error: opencv2/highgui/highgui.hpp: No such file or directory
opencv_test.c: In function ‘main’:
opencv_test.c:5: error: ‘IplImage’ undeclared (first use in this function)
opencv_test.c:5: error: (Each undeclared identifier is reported only once
opencv_test.c:5: error: for each function it appears in.)
opencv_test.c:5: error: ‘img’ undeclared (first use in this function)
opencv_test.c:9: error: ‘CV_LOAD_IMAGE_COLOR’ undeclared (first use in this function)
opencv_test.c:12: error: ‘CV_WINDOW_AUTOSIZE’ undeclared (first use in this function)

どうやら,/opt/local/include/opencv から /opt/local/include/opencv2 が見えないらしいので
$ cd /opt/local/include/opencv
$ sudo ln -s ../opencv2 ./opencv2
シンボリックリンクを貼ってやるとコンパイル成功(バッドノウハウのにおいがするが...).

サンプルプログラムと同じフォルダになんでもいいのでtest.jpgを置いて実行すると,それが表示される.


追記
perlの依存関係でうまくいかない場合の対応策
http://otonaka.blogspot.com/2011/09/macopencv.html