申明:此方法在Fedora22上安装成功
1、安装编译环境
sudo dnf install gcc gcc-c++ ncurses-devel cmake cmake-qt-gui
2、安装GTK+2.x
sudo dnf install gtk2 gtk2-devel gtk2-devel-docs
sudo dnf install libgnome-devel gnome-devel-docs
sudo dnf install zlib glib atk pango gdk-pixbuf2 gdk-pixbuf2-devel
3、安装依赖包
sudo dnf install gtk+ gtk2-devel pkgconfig python-devel python-numpydoc
sudo dnf install libavc1394 libavc1394-devel libdc1394 libdc1394-devel jasper-devel
sudo dnf install ffmpeg ffmpeg-devel openjpeg-devel libjpeg-devel libpng-devel libtiff-devel
4、解压opencv-3.0.0.zip,并且mkdir release
5、打开cmake-qt-gui
source code一栏写源码的路径
dst一栏写那个release路径
点击configure然后点generate
若显示ICV: Downloading ippicv_linux_20141027.tgz...
那么可以把之前下载好的ippicv_linux_20141027.tgz文件放到路径~/opencv-3.0.0/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b下
6、去指定安装的路径下执行
make
sudo make install
7、默认的安装路径在/usr/local下,有/usr/local/include,/usr/local/lib等路径
8、添加opencv.conf文件
sudo vim /etc/ld.so.conf.d/opencv.conf
添加内容:/usr/local/lib
10、查询包是否安装成功
输入:pkg-config --cflags opencv
显示:-I/usr/local/include/opencv -I/usr/local/include
输入:pkg-config --libs opencv
显示:-L/usr/local/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d
-lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml
-lopencv_imgproc -lopencv_flann -lopencv_core -lopencv_hal
11、测试
输入:pkg-config --modversion gtk+-2.0
显示:2.24.28
12、编译程序
g++ test.cpp -o test `pkg-config --cflags opencv` `pkg-config --libs opencv`
13、若觉得12的步骤太麻烦,那么可以用C语言写个程序如下:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char cmd[100] ="g++ `pkg-config --cflags opencv` `pkg-config --libs opencv` ";
int main(int argc, char **argv)
{
if(argc != 2)
{
printf("Usage:opencv showImage.cpp\n");
printf("This cmd is used to compile opencv\n");
return -1;
}
strcat(cmd, argv[1]);
system(cmd);
return 0;
}