ubuntu14.04 kylin版下Opencv3.1的安装

1、安装opencv所需的库(编译器、必须库、可选库)

 

详细参考了 http://www.cnblogs.com/llxrl/p/4471831.html,并根据3.1做了修改。

 

  • 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

 

[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

 

2、从官网下载最新opencv源码(这里是3.1)

 

http://opencv.org/下载

 

或者github

 

3、编译opencv

 

将opencv放至任意目录,解压

 

unzip opencv-3.1.zip

 

创建编译目录,编译

 

cd ~/opencv-3.1mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
makesudo make install

 

然后记得将其加入环境变量,这样有些框架(caffe)在调用opencv库的时候,可以找到它们。
(1)在 /etc/ld.so.cong.d/文件夹下建立opencv.conf,里面加入以下语句:


/usr/local/lib

 

(2)将/etc/bash.bashrc中最后加入下面代码:

 

1 PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
2 export PKG_CONFIG_PATH
View Code

 

如下:

(3)将Opencv中的imgcodecs__c.h和一些动态库加入到相应位置:

然后链接它们。

 

1 $ sudo cp imgcodecs_c.h /usr/local/include
2 $ sudo cp libopencv_imgcodecs.so /usr/local/lib
3 $ sudo cp libopencv_imgcodecs.so.3.0/usr/local/lib
4 $ sudo cp libopencv_imgcodecs.so.3.0.0/usr/local/lib
5 $ sudo ln -sf /usr/local/lib/libopencv_imgcodecs.so.3.0.0/usr/local/lib/libopencv_imgcodecs.so.3.0
6 $ sudo ln -sf /usr/local/lib/libopencv_imgcodecs.so.3.0/usr/local/lib/libopencv_imgcodecs.so
7 $ sudo ldconfig -v
View Code

 

 

 

 

4、测试opencv

 

(1) 创建工作目录

 

mkdir ~/opencv-lena
cd ~/opencv-lena
gedit DisplayImage.cpp

 

 

 

(2)编辑如下代码

 

 1 #include <stdio.h>#include <opencv2/opencv.hpp>using namespace cv;
 2 int main(int argc, char** argv )
 3 {
 4   if ( argc != 2 )
 5   {
 6     printf("usage: lena.out <Image_Path>\n");
 7     return -1;
 8   }
 9   Mat image;
10   image = imread( argv[1], 1 );
11   if ( !image.data )
12   {
13     printf("No image \n");
14     return -1;
15   }
16   namedWindow("lena", WINDOW_AUTOSIZE );
17   imshow("lena", image);
18   waitKey(0);
19   return 0;
20 }
View Code

 

 

 

(3)创建CMake编译文件

 

gedit CMakeLists.txt

 

写入如下内容:

 

cmake_minimum_required(VERSION 2.8)
project( lena)
find_package( OpenCV REQUIRED )
add_executable( lena lena.cpp )
target_link_libraries( lena ${OpenCV_LIBS} )

 

 

 

(4)编译

 

cd ~/opencv-lena
cmake .
make

 

(5) 执行

此时opencv-lena文件夹中已经产生了可执行文件lena,下载lena.jpg放在opencv-lena下,运行

 

./lena lena.jpg

 

(6) 结果

 

 



转载于:https://www.cnblogs.com/anmengcv/p/5368330.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值