歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Ubuntu 系統下 OpenCV 3.1.0 編譯安裝

Ubuntu 系統下opencv編譯安裝

編譯環境安裝:

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下載:

  穩定版

wget https://github.com/Itseez/opencv/archive/3.1.0.zip

  github源代碼

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

創建編譯的臨時目錄:

cd ~/opencv

mkdir build

cd build

   注意: 這裡假設opencv解壓開的或者從github獲取的源代碼目錄在用戶主目錄下。

生成cmake編譯配置:

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

編譯:

make -j4 # runs 4 jobs in parallel

安裝opencv:

sudo make install

運行測試:

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

OPENCV_TEST_DATA_PATH=~/opencv_extra

~/opencv/build/bin/opencv_test_core

一個例子:

首先創建一個目錄 test,並進入目錄:

mkdir test

cd test

其次,創建文件 DisplayImage.cpp 如下:

#include <stdio.h>

#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv )

{

    if ( argc != 2 )

    {

        printf("usage: DisplayImage.out <Image_Path>\n");

        return -1;

    }

    Mat image;

    image = imread( argv[1], 1 );

    if ( !image.data )

    {

        printf("No image data \n");

        return -1;

    }

    namedWindow("Display Image", WINDOW_AUTOSIZE );

    imshow("Display Image", image);

    waitKey(0);

    return 0;

}

接著,創建cmake配置文件 CMakeLists.txt,如下:

cmake_minimum_required(VERSION 2.8)

project( DisplayImage )

find_package( OpenCV REQUIRED )

include_directories( ${OpenCV_INCLUDE_DIRS} )

add_executable( DisplayImage DisplayImage.cpp )

target_link_libraries( DisplayImage ${OpenCV_LIBS} )

最後運行:

./DisplayImage linuxidc.jpg #隨便一張圖片都行

參考:

http://docs.opencv.org/3.1.0/d7/d9f/tutorial_linux_install.html

http://docs.opencv.org/3.1.0/db/df5/tutorial_linux_gcc_cmake.html

OpenCV官方教程中文版(For Python) PDF  http://www.linuxidc.com/Linux/2015-08/121400.htm

Ubuntu Linux下安裝OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htm

Ubuntu 12.04 安裝 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htm

CentOS下OpenCV無法讀取視頻文件 http://www.linuxidc.com/Linux/2011-07/39295.htm

Ubuntu 12.04下安裝OpenCV 2.4.5總結 http://www.linuxidc.com/Linux/2013-06/86704.htm

Ubuntu 10.04中安裝OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm

基於QT和OpenCV的人臉識別系統 http://www.linuxidc.com/Linux/2011-11/47806.htm

[翻譯]Ubuntu 14.04, 13.10 下安裝 OpenCV 2.4.9  http://www.linuxidc.com/Linux/2014-12/110045.htm

OpenCV的詳細介紹:請點這裡
OpenCV的下載地址:請點這裡

更多Ubuntu相關信息見Ubuntu 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=2

Copyright © Linux教程網 All Rights Reserved