ubuntu 16.04安装opencv3.0流程以及报错解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yiranyhy/article/details/72935499

首先安装依赖项:

1 [compiler] sudo apt-get install build-essential
2 [required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
3 [optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
然后在官网下载3.0安装包https://github.com/opencv/opencv/archive/3.0.0.zip

解压

cd ~/opencv-3.0.0
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
其中在make时会报错,


解决方法:

打开/home/yhy/opencv-3.0.0/modules/cudalegacy/src/graphcuts.cpp

把此处改为:

#include "precomp.hpp"

#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)  ||(CUDART_VERSION>=8000)

其中 ||(CUDART_VERSION>=8000)为后增加的内容


再次make,就不会报错

安装完后,修改环境变量:

sudo gedit /etc/ld.so.conf.d/opencv.conf

写入/usr/local/lib,保存

sudo ldconfig

sudo gedit /etc/bash.bashrc

在文末增加:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

保存


到此安装完成,下面开始测试安装是否成功

测试方法详见:http://www.tuicool.com/articles/nYJrYra或者另一种http://blog.csdn.net/linj_m/article/details/45048905

用第一种方法时记得在gedit CMakeLists.txt时要在内容里多加两行:

cmake_minimum_required(VERSION 2.8)

project( DisplayImage )
set(OpenCV_DIR /home/yhy/opencv-3.0.0/release)
include_directories(/usr/local/include)

find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

加粗两行为多加的,不然make会报错:

make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2

make: *** [all] Error 2

用以上方法就可以避开这个报错

以上,就可以完成opencv的安装及检测了,祝好!


没有更多推荐了,返回首页