Ubuntu14 系统下安装Opencv3.0攻略

Ubuntu14 系统下安装Opencv3.0攻略


安装准备

安装环境: Ubuntu14.0系统

安装软件:  OpenCV3.0.0 linux版本

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

  • 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


安装流程

1.更新系统

利用ubuntu自带的更新管理器或者
sudo apt-get update
sudo apt-get upgrade


2.安装依赖包。否则写OpenCV程序的时候虽然编译能通过,可能运行时出错。

sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev


3下载openCV的源码包并解压出来

   下载地址: http://sourceforge.net/projects/opencvlibrary/

解压文件:/home/workplace/opencv3.0

进入当前Opencv的文件   cd ~/opencv

创建一个文件 mkdir release

cd release

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..[网上攻略多是这条的指令]

[但是限量版在安装过程中主要是被这条指令给坑惨了]  

这条指令可能会带来以下问题。。。

可能遇到的问题:

Scanning dependencies of target opencv_core[ 10%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o
Linking CXX shared library ../../lib/libopencv_core.so
[ 15%] Built target opencv_core
[ 15%] Built target opencv_ts_pch_dephelp
[ 15%] Built target pch_Generate_opencv_ts
[ 15%] Built target opencv_imgproc_pch_dephelp
[ 15%] Built target pch_Generate_opencv_imgproc
Linking CXX shared library ../../lib/libopencv_imgproc.so
/usr/bin/ld: ../../../3rdparty/ippicv/unpack/ippicv_lnx/lib/ia32/libippicv.a(jmp_ippiResizeGetBufferSize_16s_as.s.o): relocation R_386_GOTOFF against undefined symbol `ippicvJumpIndexForMergedLibs' can not be used when making a shared object
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_imgproc.so.3.0.0] Error 1
make[1]: *** [modules/imgproc/CMakeFiles/opencv_imgproc.dir/all] Error 2
make: *** [all] Error 2

主要原因是,WITH_OFF开启了 会有一定冲突

解决办法: cmake时 添加-D  WITH_IPP=OFF即可
完整命令:cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX= /usr/local/ -D WITH_IPP=OFF ../

参考:http://answers.opencv.org/question/37115/opencv-249-make-error/

   http://blog.csdn.net/ppp2006/article/details/38819527
4. 在release目录下

 输入sudo make指令

5. sudo make install


6. 编译samples程序:

$ cd ~/opencv/samples
$ sudo cmake .
$ sudo make -j $(nproc)


测试安装结果

1) 创建工作目录

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


2) 编辑如下代码

#include
#include

using namespace cv;

int main(int argc, char** argv )
{
    if ( argc != 2 )
    {
        printf("usage: DisplayImage.out \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;
}


3) 创建CMake编译文件

gedit CMakeLists.txt

写入如下内容

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


4) 编译

cd ~/opencv-lena
cmake .
make


5) 执行

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

./DisplayImage lena.jpg


6)结果

Ubuntu14 系统下安装Opencv3.0攻略_第1张图片


版权声明:本文为博主原创文章,未经博主允许不得转载!转载需链接!








你可能感兴趣的:(技术)