OpenCV安装

复盘之前的项目,看到这个,简单写点文字记录,方便以后使用:

  • 最重要的文档:
  • 软件版本:

    • Linux[Centos6],jdk7
  • JDK && Ant 安装:
    安装JDK,并设置JAVA_HOME
    安装Ant,并设置ANT_HOME

  • 安装依赖:
    • CENTOS6
      yum install -y build-essential gcc gcc-c++ cmake git pkgconfig \
      gtk+-devel gtk2-devel \
      python python-pip python-devel python-numpy \
      gimp-devel gimp-devel-tools gimp-help-browser \
      libjpeg-devel libtiff-devel libpng-devel \
      gstreamer-devel gstreamer-plugins-base-devel libv4l ffmpeg-devel mencoder flvtool2 \
      libavc1394-devel libraw1394-devel libdc1394-devel jasper-devel jasper-utils zlib-devel \
      unzip vim
    • Ubuntu
      sudo apt-get install build-essential
      sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
      sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
  • 下载OpenCV,解压,编译安装:

    1. download:
    2. unzip opencv-3.1.0.zip
    3. cd opencv-3.1.0 && mkdir build && cd build/
    4. cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
      • python options
        • PYTHON2(3)_EXECUTABLE =
        • PYTHON_INCLUDE_DIR = /usr/include/python
        • PYTHON_INCLUDE_DIR2 = /usr/include/x86_64-linux-gnu/python
        • PYTHON_LIBRARY = /usr/lib/x86_64-linux-gnu/libpython.so
        • PYTHON2(3)_NUMPY_INCLUDE_DIRS = /usr/lib/python/dist-packages/numpy/core/include/
      • java options
        • Unset parameter: BUILD_SHARED_LIBS
        • It is useful also to unset BUILD_EXAMPLES, BUILD_TESTS, BUILD_PERF_TESTS - as they all will be statically linked with OpenCV and can take a lot of memory.
    5. demo可以作为参考

      1
      cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF  -DCMAKE_INSTALL_PREFIX=/usr/local ..
    6. 编译完成查看输出, 如果”To be built”里包含java这一项的话,就可以编译成java需要的jar和so,接下来只要make && make install
      make -j8 # 并发编译设置为CPU核心的2倍为宜
      Ubuntu 在install需要添加sudo

    7. 编译常见问题:

      • 在第4项编译的过程中,需要下载ippicv,可能下载比较慢,可以手动下载
        下载 ippicv_linux_20151201
        下载完成之后,通过md5sum ippicv_linux_20151201.tgz 检测hash值,808b791a6eac9ed78d32a7666804320e,复制到目录: 3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz
        重新编译.

      • 在编译过程中如果出现SIZE_MAX的问题,原因可能是Cmake的版本问题引起.

        /usr/include/jasper/jas_math.h:117:22: error: ‘SIZE_MAX’ was not declared in this scope

        可以在 /usr/include/jasper/jas_math.h文件的头部#include 的下面添加:
        #if ! defined SIZE_MAX
        #define SIZE_MAX (4294967295U)
        #endif
        重新编译