您的位置:首页 > 运维架构

在Ubuntu14.04.5上安装OpenCV2.4.9时遇到的各种问题

2017-06-06 19:48 567 查看
从昨天到今天

首先,我是按照这个博客进行安装的,虽然他是以Opencv3.0为样板但是安装基本都大同小异.

(博客地址:http://blog.csdn.net/dreamsky168/article/details/49928293)


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

转载请说明 http://www.cnblogs.com/llxrl/p/4471831.html

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

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
然后在进行到第二步的时候就出现了error(这是一个我最怕的单词....),报的错如下所示

Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
libgtk2.0-dev : Depends: libglib2.0-dev (>= 2.27.3) but it is not going to be installed
Depends: libgdk-pixbuf2.0-dev (>= 2.21.0) but it is not going to be installed
Depends: libpango1.0-dev (>= 1.20) but it is not going to be installed
Depends: libatk1.0-dev (>= 1.29.2) but it is not going to be installed
Depends: libcairo2-dev (>= 1.6.4-6.1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

然后参见网页(https://askubuntu.com/questions/884413/unable-to-install-libgtk2-0-dev-on-ubuntu-16-04)解决了这个问题.其实就是
sudo apt-get install libglib2.0-dev libglib2.0-0=2.48.0-1ubuntu4
 这句命令.然后再执行
sudo apt-get install libgtk2.0-dev
就可以了.

第三步倒是没有什么问题.


2、从官网下载最新opencv源码(2.4以上)

http://sourceforge.net/projects/opencvlibrary/

或者github


3、编译opencv

将opencv放至任意目录,解压

unzip opencv- 3.0. 0-rc1. zip (根据我的实际情况,这里是OpenCV-2.4.9)

创建编译目录,编译
 1 cd ~/opencv-2.4.9
 2 mkdir release
 3 cd release
 4 cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
 5 make
 6 sudo make install

然后这里的第5步又出错了....但根据博客'unspported gpu architecture compute_11 解决办法'(http://blog.csdn.net/sysuwuhongpeng/article/details/45485719)应该是在第4步上做修改



将第4步改为[code] cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler ..  

[/code]
这个问题就可以解决了~

之后再次运行[code]make
还是有问题,只不过是其他地方出了问题.[/code]
/home/ubuntu/opencv-2.4.9/modules/gpu/src/nvidia/core/NCVPixelOperations.hpp(51): error: a storage class is not allowed in an explicit specialization
参考网页(https://devtalk.nvidia.com/default/topic/793805/opencv-2-4-9-won-t-compile/?offset=2)把NCVPixelOperations.hpp里的 template function中关键字"static"全部去掉这个问题就解决了(注意,文件中其他地方的"static"还是保留的).

  
同样,再次运行make这个过程就很慢,然后很不幸地又发现了错误,不过这也在意料之中哦.经过上面几次折腾出现错误也不慌了.报错如下:
modules/cudalegacy/src/graphcuts.cpp:120:54: error:
‘NppiGraphcutState’ has not been declared
typedef NppStatus (*init_func_t)(NppiSize oSize,
NppiGraphcutState** ppState, Npp8u* pDeviceMem);
这是因为opecv3.0与cuda8.0不兼容导致的。解决办法:

修改 ~/opencv/modules/cudalegacy/src/graphcuts.cpp文件内容,如图:

有类似错误的文件只要修改这一个文件就好.
后面make就畅通无阻了,哈哈哈哈哈哈.

4、测试opencv

1) 创建工作目录

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




















2) 编辑如下代码

#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;
}


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下,运行



























附上这次所有帮助我解决一切问题的网址:
http://blog.csdn.net/sysuwuhongpeng/article/details/45485719  https://ubuntuforums.org/showthread.php?t=2244063 https://devtalk.nvidia.com/default/topic/793805/opencv-2-4-9-won-t-compile/?offset=2 https://askubuntu.com/questions/884413/unable-to-install-libgtk2-0-dev-on-ubuntu-16-04





































                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息