在ubuntu14.04下安装Opencv3,遇到了许多不明白的问题,第一次安装成功了
一 按照官网安装Opencv步骤:
1.需要的包:
GCC 4.4.x 或更高
CMake 2.8.7 或更高
Git
GTK+2.x 或更高,包括头(libgtk2.0-dev)
pkg-config
Python 2.6 或以后,Numpy 1.5或以后,和开发包(python-dev,python-numpy)
ffmpeg 或者libav开发包:libavcodec-dev, libavformat-dev, libswscale-dev
可选包:libtbb2 ,libtbb-dev
可选包:libdc1394 2.x
可选包:libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
可以用一下代码进行安装:
基本:
sudo apt-get install build-essential
必须:
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
可选:
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.0.0.zip,也可以自行上opencv官网下载http://opencv.org/。
解压安装包到你想要的地方,本文以存放主文件加下。
mkdir opencv-
3.1
.
0
cd /opencv-
3.1
.
0
/
将opencv解压
unzip opencv- 3.0. 0-rc1. zip
3. 利用终端进入opencv3文件夹,代码如下:
cd ~/opencv-3.0.0
4. 新建build文件夹存放opencv的编译文件,进入build文件夹代码如下
mkdir build
cd build
5. 配置opencv文件,代码如下:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
或者使用cmake-gui用图形界面编译。
6. 进行编译,代码如下:
make
7. 安装opencv库到系统,代码如下:
sudo make install
这样OpenCV就可以使用了。
二 测试
mkdir ~/opencv-lena
cd ~/opencv-lena
gedit DisplayImage.cpp
#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;
}
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} )
cd ~/opencv-lena
cmake .
make
此时opencv-lena文件夹中已经产生了可执行文件DisplayImage,下载lena.jpg放在opencv-lena下,运行
./DisplayImage lena.jpg
三 问题
以上就是OpenCV安装全过程,安装过程中可能碰到一些问题,例举一些。
在编译的过程中可能会碰到找不到Qt5文件的情况,只是一个警告可以不理,如果有强迫症的同学可以安装一下Qt5
CMake Warning at cmake/OpenCVFindLibsGUI.cmake:18 (find_package):
By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5Core", but
CMake did not find one.
另一个是ICV hash校验值不符的问题
CMake Warning at 3rdparty/ippicv/downloader.cmake:54 (message):
ICV: Local copy of ICV package has invalid MD5 hash:
0103b909e19ca9c6497a7ae696c16480 (expected:
8b449a536a2157bcad08a2b9f266828b)
Call Stack (most recent call first):
3rdparty/ippicv/downloader.cmake:108 (_icv_downloader)
cmake/OpenCVFindIPP.cmake:235 (include)
cmake/OpenCVFindLibsPerf.cmake:12 (include)
CMakeLists.txt:526 (include)
-- ICV: Downloading ippicv_linux_20141027.tgz...
CMake Error at 3rdparty/ippicv/downloader.cmake:71 (file):
file DOWNLOAD HASH mismatch
for file: [/home/jason/program/opencv-3.0.0/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b/ippicv_linux_20141027.tgz]
expected hash: [8b449a536a2157bcad08a2b9f266828b]
actual hash: [0103b909e19ca9c6497a7ae696c16480]
Call Stack (most recent call first):
3rdparty/ippicv/downloader.cmake:108 (_icv_downloader)
cmake/OpenCVFindIPP.cmake:235 (include)
cmake/OpenCVFindLibsPerf.cmake:12 (include)
CMakeLists.txt:526 (include)
之后查了很多资料也没有发现也不知道该怎么解决,后来去查了一下代码,发现这个是下载ippicv_linux_20141027.tgz时的校验和不符,查看了配置文件,发现可以自行从http://sourceforge.net/projects/opencvlibrary/files/3rdparty/ippicv这里下载,奇怪的是编译时从这里下载的文件和自己下载的文件校验值居然不一样,也真是神奇,将下载的文件
~/opencv-3.0.0/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b ,代替原来的同名文件,ok问题解决。