zoukankan      html  css  js  c++  java
  • 源码编译opencv-python

    Building OpenCV from source

    Compiling from source may seem a little complicated at first, but once you succeeded in it, there is nothing complicated.

    First we will install some dependencies. Some are required, some are optional. You can skip optional dependencies if you don't want.

    Required build dependencies

    We need CMake to configure the installation, GCC for compilation, Python-devel and Numpy for building Python bindings etc.

    sudo apt-get install cmake
    sudo apt-get install gcc g++

    to support python2:

    sudo apt-get install python-dev python-numpy

    to support python3:

    sudo apt-get install python3-dev python3-numpy

    Next we need GTK support for GUI features, Camera support (v4l), Media Support (ffmpeg, gstreamer) etc.

    sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
    sudo apt-get install libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev

    to support gtk2:

    sudo apt-get install libgtk2.0-dev

    to support gtk3:

    sudo apt-get install libgtk-3-dev

    Optional Dependencies

    Above dependencies are sufficient to install OpenCV in your Ubuntu machine. But depending upon your requirements, you may need some extra dependencies. A list of such optional dependencies are given below. You can either leave it or install it, your call :)

    OpenCV comes with supporting files for image formats like PNG, JPEG, JPEG2000, TIFF, WebP etc. But it may be a little old. If you want to get latest libraries, you can install development files for system libraries of these formats.

    sudo apt-get install libpng-dev
    sudo apt-get install libjpeg-dev
    sudo apt-get install libopenexr-dev
    sudo apt-get install libtiff-dev
    sudo apt-get install libwebp-dev
    Note
    If you are using Ubuntu 16.04 you can also install to add a system level support for the JPEG2000 format.libjasper-dev

    Downloading OpenCV

    To download the latest source from OpenCV's GitHub Repository. (If you want to contribute to OpenCV choose this. For that, you need to install Git first)

    $ sudo apt-get install git
    $ git clone https://github.com/opencv/opencv.git

    It will create a folder "opencv" in current directory. The cloning may take some time depending upon your internet connection.

    Now open a terminal window and navigate to the downloaded "opencv" folder. Create a new "build" folder and navigate to it.

    $ mkdir build
    $ cd build

    Configuring and Installing

    Now we have all the required dependencies, let's install OpenCV. Installation has to be configured with CMake. It specifies which modules are to be installed, installation path, which additional libraries to be used, whether documentation and examples to be compiled etc. Most of this work are done automatically with well configured default parameters.

    Below command is normally used for configuration of OpenCV library build (executed from build folder):

    $ cmake ../

    OpenCV defaults assume "Release" build type and installation path is "/usr/local". For additional information about CMake options refer to OpenCV C++ compilation guide:

    You should see these lines in your CMake output (they mean that Python is properly found):

    -- 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
    --
    -- Python 3:
    -- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
    -- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
    -- numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.8.2)
    -- packages path: lib/python3.4/dist-packages

    Now you build the files using "make" command and install it using "make install" command.

    $ make
    # sudo make install

    Installation is over. All files are installed in "/usr/local/" folder. Open a terminal and try import "cv2".

    import cv2 as cv
    print(cv.__version__)

    --摘自opencv官方文档 

    没伞的孩子,就要学会在雨中奔跑!
  • 相关阅读:
    [Android Studio] Android Studio底边栏选项不见了,如何调出来
    [Android Studio] Android Studio中查看类的继承关系
    [Android Studio] Android Studio如何提示函数用法
    [Android Studio] Android Studio如何查看branch列表及切换branch(转载)
    [Android Studio] Android Studio使用教程(二)
    [Android Studio] Android Studio使用教程(一)
    [Android Studio] Android Studio移除的Module如何恢复(转载)
    [Android Studio] Android Studio如何删除module(转载)
    [Linux] ubuntu下查看CHM的软件
    python 在Windows中描述路径时出现的问题
  • 原文地址:https://www.cnblogs.com/mikigo/p/13745612.html
Copyright © 2011-2022 走看看