fedora24下编译安装OpenCV-3.1.0

1、安装编译环境
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ sudo dnf install gcc gcc-c++ ncurses-devel cmake  

2、安装gtk+2.x
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ sudo dnf install gtk2 gtk2-devel gtk2-devel-docs  
  2. $ sudo dnf install libgnome-devel gnome-devel-docs  
  3. $ sudo dnf install zlib glib atk pango gdk-pixbuf2 gdk-pixbuf2-devel  

3、安装依赖的包
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ sudo dnf install gtk+ gtk2-devel pkgconfig python-devel python-numpydoc  
  2. $ sudo dnf install libavc1394 libavc1394-devel libdc1394 libdc1394-devel jasper-devel  
  3. $ sudo dnf install ffmpeg ffmpeg-devel openjpeg-devel libjpeg-devel libpng-devel libtiff-devel  

4、最后,就是OpenCV的安装包了,去官网下载即可,传送门: http://opencv.org/

使用cmake生成用于编译安装的makefile文件


解压包后按顺序执行以下命令
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ cd ~/opencv-3.1.0/  
  2. $ cmake -DINSTALL_CREATE_DISTRIB=ON  
  3. $ make  
  4. $ sudo make install  

opencv会默认安装在/usr/local/目录文件下,若要改变安装位置有选项“-D CMAKE_INSTALL_PREFIX=/usr/local",修改后面的参数即可。
其中命令"cmake -DINSTALL_CREATE_DISTRIB=ON"是必须要加上的,否则编译以后目标文件链接库的时候会出现以下错误
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. /usr/bin/ld: cannot find -lippicv  
  2. collect2: error: ld returned 1 exit status  

环境配置

1、添加环境变量profile
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ sudo vim /etc/profile  
在最后添加如下内容
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  
  2. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib  
保存并退出,并执行以下命令使修改生效
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ sudo source /etc/profile  

2、添加另一个环境变量bashrc
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ sudo vim /etc/bashrc  
在最后添加如下内容
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  
  2. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib  
保存并退出,并执行以下命令使修改生效
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ sudo source /etc/bashrc  

3、最后执行
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ sudo ldconfig  


测试

1、首先检查测试是否安装成功
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ pkg-config --cflags opencv  
  2. -I/usr/local/include/opencv -I/usr/local/include   
  3. $ pkg-config --libs opencv  
  4. -L/usr/local/lib -lopencv_world   
  5. $ pkg-config --modversion gtk+-2.0  
  6. 2.24.29  


2、写一个程序测试test.cpp,源代码如下
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. #include "opencv/cv.h"  
  2. #include "opencv/highgui.h"  
  3. int main(int argc, char **argv)  
  4. {  
  5.         IplImage* pImage;  
  6.         if(argc==2 && (pImage=cvLoadImage(argv[1],1))!=0)  
  7.         {  
  8.                 cvNamedWindow("Image",1);  
  9.                 cvShowImage("Image",pImage);  
  10.                 cvWaitKey(0);  
  11.                 cvDestroyWindow("Image");  
  12.                 cvReleaseImage(&pImage);  
  13.                 return 0;  
  14.         }  
  15.         return -1;  
  16. }  


直接编译
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ g++ `pkg-config --cflags opencv` -o test test.cpp `pkg-config --libs opencv`  


或者编译链接分两部完成
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ g++ `pkg-config --cflags opencv` -c test.cpp  
  2. $ g++ `pkg-config --libs     opencv` -o test test.o  

最后运行
[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ ./test Lenna.jpg  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值