Fedora 23下编译安装OpenCV-3.1.0所需环境
1、安装编译环境
$ sudo dnf install gcc gcc-c++ ncurses-devel cmake
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的安装包了,去官网下载即可,传送门:http://opencv.org/
使用cmake生成用于编译安装的makefile文件
解压包后按顺序执行以下命令
$ cd ~/opencv-3.1.0/
$ cmake -DINSTALL_CREATE_DISTRIB=ON
$ make
$ sudo make install
opencv会默认安装在/usr/local/目录文件下,若要改变安装位置有选项“-D CMAKE_INSTALL_PREFIX=/usr/local”,修改后面的参数即可。
其中命令”cmake -DINSTALL_CREATE_DISTRIB=ON”是必须要加上的,否则编译以后目标文件链接库的时候会出现以下错误
/usr/bin/ld: cannot find -lippicv
collect2: error: ld returned 1 exit status
具体请走传送门:https://github.com/Itseez/opencv/issues/5852
环境配置
1、添加环境变量profile
$ sudo vim /etc/profile
在最后添加如下内容
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
保存并退出,并执行以下命令使修改生效
$ sudo source /etc/profile
2、添加另一个环境变量bashrc
$ sudo vim /etc/bashrc
在最后添加如下内容
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
保存并退出,并执行以下命令使修改生效
$ sudo source /etc/bashrc
3、最后执行
$ sudo ldconfig
测试
1、首先检查测试是否安装成功
$ pkg-config –cflags opencv
-I/usr/local/include/opencv -I/usr/local/include
$ pkg-config –libs opencv
-L/usr/local/lib -lopencv_world
$ pkg-config –modversion gtk+-2.0
2.24.29
2、写一个程序测试test.cpp,源代码如下
#include “opencv/cv.h”
#include “opencv/highgui.h”
int main(int argc, char **argv)
{
IplImage* pImage;
if(argc==2 && (pImage=cvLoadImage(argv[1],1))!=0)
{
cvNamedWindow(“Image”,1);
cvShowImage(“Image”,pImage);
cvWaitKey(0);
cvDestroyWindow(“Image”);
cvReleaseImage(&pImage);
return 0;
}
return -1;
}
直接编译
$ g++ `pkg-config –cflags opencv` -o test test.cpp `pkg-config –libs opencv`
或者编译链接分两部完成
$ g++ `pkg-config –cflags opencv` -c test.cpp
$ g++ `pkg-config –libs opencv` -o test test.o
最后运行
$ ./test Lenna.jpg
OpenCV官方教程中文版(For Python) PDF http://www.linuxidc.com/Linux/2015-08/121400.htm
Ubuntu 14.04安装OpenCV2.4.9 http://www.linuxidc.com/Linux/2016-07/132884.htm
Ubuntu 16.04上用CMake图形界面交叉编译树莓派的OpenCV3.0 http://www.linuxidc.com/Linux/2016-10/135914.htm
Ubuntu 16.04中安装OpenCV 2.4.11 http://www.linuxidc.com/Linux/2016-07/132882.htm
Ubuntu 16.04下Matlab2014a+Anaconda2+OpenCV3.1+Caffe安装 http://www.linuxidc.com/Linux/2016-07/132860.htm
Linux上安装和编译OpenCV3.0.0 http://www.linuxidc.com/Linux/2017-07/145446.htm
Ubuntu 16.04下OpenCV安装笔记和例程 http://www.linuxidc.com/Linux/2017-08/146027.htm
Ubuntu 16.04下TensorFlow+Caffe+OpenCV3.1+Theano部署 http://www.linuxidc.com/Linux/2017-01/139503.htm
Ubuntu 16.04 编译安装OpenCV 3.1及OpenCV多版本切换 http://www.linuxidc.com/Linux/2017-01/139325.htm
[翻译]Ubuntu 14.04, 13.10 下安装 OpenCV 2.4.9 http://www.linuxidc.com/Linux/2014-12/110045.htm
Ubuntu 安装 OpenCV 2.4.9 http://www.linuxidc.com/Linux/2016-12/138293.htm
Ubuntu 17.04下OpenCV源码编译安装 http://www.linuxidc.com/Linux/2017-10/147316.htm
OpenCV的详细介绍:请点这里
OpenCV的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-10/147622.htm