参考URL
親方そのまんまじゃないですかぁ
Installing OpenCV 3.0.0 on Ubuntu 14.04 » Rodrigo Berriel
環境
手順
依存ライブラリをインストール 当然apt-get update
とapt-get upgrade
程度はしておくこと。
sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff4-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip
適当なところでソースをダウンロード
wget https://github.com/Itseez/opencv/archive/3.0.0.zip -O opencv-3.0.0.zip unzip opencv-3.0.0.zip
すごくダウンロードに時間かかる場合はSourceForgeからの方がいいかもしれない
いざコンパイル 結構時間かかる
cd opencv-3.0.0 mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D WITH_TBB=ON \ -D WITH_V4L=ON \ -D OPENCV_EXTRA_MODULES_PATH=./opencv_contrib/modules .. make -j $(nproc) sudo make install
ライブラリの読み込み処理
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf' sudo ldconfig
これで終了
SIFT・SURFを使えるようにする(non-free)
SIFT・SURFなどの特許の絡むモジュール(いわゆるnon-free)は別のレポジトリに格納されている
先ほどのopencv-3.0.0/buildにて
git clone --depth 1 https://github.com/Itseez/opencv_contrib.git
あとはさっきのcmake時に-D OPENCV_EXTRA_MODULES_PATH=opencv_contrib/modules
を追加してあげる
Pythonのライブラリが無いって怒られる
失敗例
-- Found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.6", minimum required is "2.7") -- Could NOT find PythonLibs (missing: PYTHON_INCLUDE_DIRS) (found suitable exact version "2.7.6") -- Found PythonInterp: /usr/bin/python3.4 (found suitable version "3.4", minimum required is "3.4") -- Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) (Required is exact version "3.4.0") <略> -- Python 2: -- Interpreter: /usr/bin/python2.7 (ver 2.7.6) -- Libraries: NO -- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2) -- packages path: lib/python2.7/dist-packages
以下のように設定してあげる
export PYTHON_INCLUDE_DIRS=/usr/include/python2.7 export PYTHON_LIBRARYS=/usr/lib/x86_64-linux-gnu/libpython2.7.so
設定後はキャッシュが残ってるので必ずbuild/CMakeCache.txt
を削除しておくこと!
おkな例
-- Found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.6", minimum required is "2.7") -- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found suitable exact version "2.7.6") -- Found PythonInterp: /usr/bin/python3.4 (found suitable version "3.4", minimum required is "3.4") -- Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) (Required is exact version "3.4.0") <略> -- Python 2: -- Interpreter: /usr/bin/python2.7 (ver 2.7.6) -- Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.6) -- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2) -- packages path: lib/python2.7/dist-packages
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
って言われるけど3.xの話だから関係ない
確認
$ python Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cv2
libdc1394 error: Failed to initialize libdc1394って怒られる
sudo ln /dev/null /dev/raw1394