opencv 2.4.9をmakeする作戦で進める
debianは空の状態から作業開始.まずはupdateと必要なものをinstall
$ sudo apt-get -yV update
$ sudo apt-get -yV upgrade
$ sudo apt-get install cmake
$ sudo apt-get install g++
$ sudo apt-get install gcc
$ sudo apt-get install unzip
次にopencvを落としてきて、cmake
-> make
$ wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip
$ unzip opencv-2.4.9.zip
$ cd opencv-2.4.9/
$ mkdir release
$ cd release
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..
$ make
そうすると、以下のようなログを出して失敗
・
・
・
Linking CXX static library ../../lib/libopencv_ocl_pch_dephelp.a
[ 67%] Built target opencv_ocl_pch_dephelp
Scanning dependencies of target pch_Generate_opencv_ocl
[ 67%] Generating precomp.hpp
[ 67%] Generating precomp.hpp.gch/opencv_ocl_RELEASE.gch
[ 68%] Built target pch_Generate_opencv_ocl
[ 68%] Generating opencl_kernels.cpp, opencl_kernels.hpp
CMake Error at /home/vagrant/opencv-2.4.9/cmake/cl2cpp.cmake:50 (string):
string does not recognize sub-command MD5
make[2]: *** [modules/ocl/opencl_kernels.cpp] Error 1
make[1]: *** [modules/ocl/CMakeFiles/opencv_ocl.dir/all] Error
MD5をrecognizeできないと言うので、md5のパッケージを入れてから再度makeする
$ sudo apt-get install isomd5sum
$ make
だが、ログのメッセージは変わらず失敗
その後、cmakeのバージョンが古いため発生することを知る
cmakeの新しいバージョンをinstall
# 失敗したcmakeのversion
$ cmake --version
cmake version 2.8.2
$ cd
$ mkdir cmakebuild
$ cd cmakebuild/
$ wget http://www.cmake.org/files/v2.8/cmake-2.8.11.2.tar.gz
$ tar xvzf cmake-2.8.11.2.tar.gz
$ cd cmake-2.8.11.2/
$ ./configure
$ make
$ sudo make install
cmakeのversionをあげたので、再びopencvのcmakeから行う
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..
そしてそのログ
-- The CXX compiler identification is GNU 4.4.5
-- The C compiler identification is GNU 4.4.5
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detected version of GNU GCC: 44 (404)
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR)
-- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)
-- Found JPEG: libjpeg
-- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR)
-- Found ZLIB: zlib (found version "1.2.7")
-- Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR)
-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - found
-- Looking for sys/videoio.h
-- Looking for sys/videoio.h - not found
-- Looking for libavformat/avformat.h
-- Looking for libavformat/avformat.h - not found
-- Looking for ffmpeg/avformat.h
-- Looking for ffmpeg/avformat.h - not found
-- Found PythonInterp: /usr/bin/python2.6 (found suitable version "2.6.6", minimum required is "2.0")
-- Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) (Required is exact version "2.6.6") [87/1904]
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named numpy.distutils
-- Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
・
・
・
ログから、足りないらしいものをいくつか入れる
$ sudo apt-get install python-numpy
$ sudo apt-get install python-dev
$ easy_install pip
$ ln -sv /usr/local/bin/pipxx /usr/bin/pip
$ pip install pip --upgrade
もう一度 cmake
-> make
$ cd opencv-2.4.9/release
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..
$ make
・
・
・
Scanning dependencies of target example_ocl_surf_matcher
[ 99%] Building CXX object samples/ocl/CMakeFiles/example_ocl_surf_matcher.dir/surf_matcher.cpp.o
Linking CXX executable ../../bin/ocl-example-surf_matcher
[ 99%] Built target example_ocl_surf_matcher
Scanning dependencies of target example_ocl_tvl1_optical_flow
[100%] Building CXX object samples/ocl/CMakeFiles/example_ocl_tvl1_optical_flow.dir/tvl1_optical_flow.cpp.o
Linking CXX executable ../../bin/ocl-example-tvl1_optical_flow
[100%] Built target example_ocl_tvl1_optical_flow
ようやくうまくいったので、インストール
$ sudo make install
最後にcv2をimportできるかを確認
$ python
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
OK! おしまい
蛇足
以下のようにimport cv2
が失敗するときは、/usr/local/lib/python2.6/site-packages/
の下にcv2.so
が無いから。
$ python []
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2