zoukankan      html  css  js  c++  java
  • OpenCV在Linux上的安装及初试

    // linux opencv安装及初试
    // 2015.11.20 created by Huangtao

    官方教程:
    =========
    Installation in Linux
    These steps have been tested for Ubuntu 10.04 but should work with other distros as well.

    Required Packages
    GCC 4.4.x or later
    CMake 2.6 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
    The packages can be installed using a terminal and the following commands or by using Synaptic Manager:

    [compiler] sudo apt-get install build-essential
    [required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
    [optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
    Getting OpenCV Source Code
    You can use the latest stable OpenCV version available in sourceforge or you can grab the latest snapshot from our Git repository.

    Getting the Latest Stable OpenCV Version
    Go to our page on Sourceforge;
    Download the source tarball and unpack it.
    Getting the Cutting-edge OpenCV from the Git Repository
    Launch Git client and clone OpenCV repository

    In Linux it can be achieved with the following command in Terminal:

    cd ~/<my_working _directory>
    git clone https://github.com/Itseez/opencv.git
    Building OpenCV from Source Using CMake, Using the Command Line
    Create a temporary directory, which we denote as <cmake_binary_dir>, where you want to put the generated Makefiles, project files as well the object files and output binaries.

    Enter the <cmake_binary_dir> and type

    cmake [<some optional parameters>] <path to the OpenCV source directory>
    For example

    cd ~/opencv
    mkdir release
    cd release
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
    Enter the created temporary directory (<cmake_binary_dir>) and proceed with:

    make
    sudo make install
    Note If the size of the created library is a critical issue (like in case of an Android build) you can use the install/strip command to get the smallest size as possible. The stripped version appears to be twice as small. However, we do not recommend using this unless those extra megabytes do really matter
    ------------------------------------------------------------------------------------


    我在ubuntu14上的成功安装方法:
    =============================
    安装官方教程,先安装依赖库:
    apt-get install build-essential
    apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
    apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
    接下来,自己也编译过,但最后都失败。
    所以最后就直接利用:
    apt-get install libopencv-dev
    查看版本号:
    pkg-config --modversion opencv
    2.4.8
    理论上opencv安装好了,应出现以下文件:
    在/usr/local/lib应该出现以下链接库:
    libcvaux.so -> libcvaux.so.2.0
    libcvaux.so.2.0 -> libcvaux.so.2.0.0
    libcvaux.so.2.0.0
    libcv.so -> libcv.so.2.0
    libcv.so.2.0 -> libcv.so.2.0.0
    libcv.so.2.0.0
    libcxcore.so -> libcxcore.so.2.0
    libcxcore.so.2.0 -> libcxcore.so.2.0.0
    libcxcore.so.2.0.0
    libhighgui.so -> libhighgui.so.2.0
    libhighgui.so.2.0 -> libhighgui.so.2.0.0
    libhighgui.so.2.0.0
    libml.so -> libml.so.2.0
    libml.so.2.0 -> libml.so.2.0.0
    libml.so.2.0.0
    在/usr/local/include/opencv或opencv2应该出现以下头文件:
    cvaux.h, cvcompat.h, cv.hpp, cvver.h, cvwimage.h, cxcore.hpp, cxflann.h,
    cxmisc.h, cxtypes.h, highgui.hpp, cvaux.hpp, cv.h, cvtypes.h, cvvidsurv.hpp,
    cxcore.h, cxerror.h, cxmat.hpp, cxoperations.hpp, highgui.h, ml.h
    不过在我的目录下只有头文件没有链接文件,
    /usr/include/下有opencv和opencv2
    /usr/local/include/也有opencv和opencv2,但opencv下是空的。
    不过测试程序还是可以运行的。
    编译:
    g++ `pkg-config --cflags opencv` main.cpp `pkg-config --libs opencv` -o main


    我在树莓派上安装opencv;
    =======================
    安装好镜像正常启动后,
    添加apt-get源:
    nano /etc/apt/sources.list
    删除原文件所有内容,用以下内容取代:
    deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ wheezy main non-free contrib
    deb-src http://mirrors.ustc.edu.cn/raspbian/raspbian/ wheezy main non-free contrib

    apt-get update
    apt-get install build-essential
    apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
    apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
    apt-get install libopencv-dev
    查看版本:
    pkg-config --modversion opencv
    2.4.1
    插入U盘:在我的树莓派上,/media/下出现U盘,复制已经写好的源文件和jpg图片。
    编译:
    g++ `pkg-config --cflags opencv` main.cpp `pkg-config --libs opencv` -o main
    运行:
    ./main
    正常,运行成功!

  • 相关阅读:
    iOS开发数据库篇—FMDB简单介绍
    SQLite简单介绍
    iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
    使用Block在两个界面之间传值
    ios NSURLSession使用说明及后台工作流程分析
    iOS archiveRootObject 归档失败问题
    iOS开发UI篇—ios应用数据存储方式(归档)
    iOS archive(归档)
    CoreData数据库升级
    iOS开发过程中使用Core Data应避免的十个错误
  • 原文地址:https://www.cnblogs.com/ht-beyond/p/4989739.html
Copyright © 2011-2022 走看看