ubuntu16.04 + opencv3.2.0 安装教程

0、安装前准备:

(1)安装编译工具

sudo apt-get install build-essential -y

(2)安装依赖包

sudo apt-get install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev -y

(3)安装可选包

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev -y

sudo apt-get install libgtk2.0-dev -y

sudo apt-get install pkg-config -y

 

1、从GitHub下载opencv3.2.0并解压

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

unzip 3.2.0.zip

 2、进入OpenCV的目录下,编译安装OpenCV 3.2.0 源码。

cd opencv-3.2.0/

mkdir build

cd build

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

make

sudo make install

3、配置OpenCV环境变量,将opencv的库加入到路径,从而让系统可以找到。

sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'

sudo ldconfig 

4、使配置生效

sudo gedit /etc/bash.bashrc 

末尾加入
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH
保存退出

sudo source /etc/bash.bashrc 

5、测试实例

//文件名test_lena.cpp
#include 
#include 
using namespace cv;

int main( )
{
    Mat image;

    //按照自己的目录
    image = imread("/home/ross/opencv-3.2.0/samples/data/lena.jpg", 1 );
    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }
    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", image);
    waitKey(0);
    return 0;
}

(1)编译

g++ test_lena.cpp -o lena.o  `pkg-config --cflags --libs opencv`

(2)运行

./lena.o

(3)效果如图

 

 

你可能感兴趣的:(计算机视觉)