美文网首页
Ubuntu 16.04 Opencv3.1.0 + Contr

Ubuntu 16.04 Opencv3.1.0 + Contr

作者: 肥猫有梦想 | 来源:发表于2019-05-10 15:32 被阅读0次

    Firstly I used Anaconda3 to create an environment and install opencv with contirb but failed. I tried 3.4.3 and 3.1.0, all faild in cmake. At last I unload Anaconda3 and this time I succeed. 

    1.Prepare:

    依赖关系:

    GCC 4.4.x or later

    CMake 2.8.7 or higher

    Git

    GTK+2.x or higher, including headers (libgtk2.0-dev)

    pkg-config

    Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)

    ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev

    [optional] libtbb2 libtbb-dev

    [optional] libdc1394 2.x

    [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev

    注:官方文档中虽然说其中一些依赖包是可选的,但是最好还是都装上,以防出问题。

    以上依赖包可用以下命令安装:

    sudoapt-get install build-essential

    sudo apt-get install cmake

    git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

    sudo apt-get installpython-dev

    python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

    下载源码:

    a.可以从opencv官网直接下载:http://opencv.org/downloads.html

    b.也可以从github上clone:

    cd~/<my_working_directory>  //比如工作目录为opencv即,cd~/opencv

    git clone https://github.com/Itseez/opencv.git

    git clone https://github.com/Itseez/opencv_contrib.git

    2 Cmake:

    建立一个编译目录(例如:/build)把cmake后的文件都放在这里边。

    cd~/opencv

    mkdirbuild  //建立一个build目录,把cmake的文件都放着里边

    cdbuild   //进入build目录

    文件目录结构如下

    opencv

    --3rdpary ...and so on

    ---opencv_contrib

    ---build

    然后开始cmake,这里需要注意几个cmake的参数,比较重要。

    cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local-D

    OPENCV_EXTRA_MODULES_PATH=<path to opencv_contrib/modules/> ..

    注:命令中最后的"  .. "(空格+两个点)千万不要忘记

    其中 CMAKE_BUILD_TYPE=Release / Debug

    OPENCV_EXTRA_MODULES_PATH 就是用来指定要编译的扩展模块,后边加上刚下载的opencv_contrib模块的路径即可。

    这里官方文档上还给出了其他一些参数,但是我没用过,这里就不再描述了。有需要的可以查看http://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html

    进入上述中新建的build文件目录中 my commands:

    cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib/modules/ -D CMAKE_INSTALL_PREFIX=/usr/local ..

    if cmake succees, here you will see Congfigure done

    3 make&insatall:

    把代码编译成可执行文件,这里官方推荐使用多进程编译,推荐七个进程:

    make -j7

    并行运行七个jobs,这一步也在build目录中进行

    here I got an error in 100%... : opencv hdf5.h: 没有那个文件或目录

    and solved:

    dirty hardcoding

    find_package(HDF5)

    include_directories(${HDF5_INCLUDE_DIRS})

    into modules/python/common.cmake

    install:

    sudo make install

    相关文章

      网友评论

          本文标题:Ubuntu 16.04 Opencv3.1.0 + Contr

          本文链接:https://www.haomeiwen.com/subject/jkeaoqtx.html