Linux下配置OpenCV1.0环境

自己一直嚷嚷着打算学学图像识别,识别个简单的,车牌号,验证码之类的,之前查过资料,OpenCV可以实现。昨天花了一个下午终于配置好环境了,今天写下总结。

OpenCV这一名称包含了Open和Computer Vision两者的意思。实际上,Open指Open Source(开源,即开放源代码),Computer Vision则指计算机视觉。更详细介绍,请参考:http://zh.wikipedia.org/wiki/OpenCV

配置环境系统信息:Linux

[email protected]:~$ cat /etc/debian_version
7.6
[email protected]:~$ cat /proc/version
Linux version 3.2.0-4-amd64 ([email protected]) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP Debian 3.2.60-1+deb7u1
[email protected]:~$

OpenCV版本:1.0

为何选择1.0进行安装?

由于我想实现的功能比较简单,简单查资料发现最新的OpenCV2.4.9版本中添加了C++的库,我是C++渣渣,手里的书又都是1.0版本的,比较老,所以果断安装版本选择了1.0.

为何选择在Linux上安装?

在Windows上安装,有很全的资料和教程,但版本已经妥协到1.0了,正好Linux上安装业忘得差不多了,再者,个人认为,在Linux下安装成功,Windows上应该也可以,反之,未必,所以选择在Linux上安装。

好了,废话不多说,开始安装。(为了节约时间,强烈建议先看完教程再安装)

第一步:获取安装包

到http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/1.0/ 下载opencv-1.0.0.tar.gz源代码包或者到http://opencv.org/downloads.html的最下方下载

第二步:解压

首先请切换到root用户,然后,找到下载的位置

#cd /home/YOUR_USER_NAME/Downloads/

#tar -zxvf opencv-1.0.0.tar.gz

这个时候,在当前目录下会出现一个名为:opencv-1.0.0的directory

#cd opencv-1.0.0

第三步:执行./configure

#./configure

执行这条命令后,我并不顺利,报了一些错误:

提示你安装一些你需要的库,我安装了两个,就没报错了

#apt-get install g++

#apt-get install pkg-config

第四步:执行./configure,若出现以下信息,表示成功:

#./configure

General configuration ================================================
Compiler: g++
CXXFLAGS: -Wall -fno-rtti -pipe -O3 -fomit-frame-pointer

Install path: /usr/local

HighGUI configuration ================================================

Windowing system --------------
Use Carbon / Mac OS X: no
Use gtk+ 2.x: yes
Use gthread: yes

Image I/O ---------------------
Use libjpeg: yes
Use zlib: yes
Use libpng: yes
Use libtiff: yes
Use libjasper: yes
Use libIlmImf: no

Video I/O ---------------------
Use QuickTime / Mac OS X: no
Use xine: no
Use ffmpeg: no
Use dc1394 & raw1394: no
Use v4l: no
Use v4l2: yes

Wrappers for other languages =========================================
SWIG
Python no

Additional build settings ============================================
Build demo apps yes

Now run make ...

第五步:运行make

#make

make后出现以下错误信息:

../../cxcore/include/cxmisc.h:133:6: error : #elif with no expression

原因分析:
GCC 4.4 will introduce better checks in the preprocessor. The problem
is pretty obvious: you‘re using a #elif without any condition when
you really want a #else.

You can reproduce this problem with gcc-snapshot from unstable.

> Automatic build of opencv_1.0.0-6.1 on em64t by sbuild/amd64 0.53
...
> /bin/sh ../../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I../.. -I. -I../../cxcore/include -I../.. -DNDEBUG -fno-strict-aliasing -Wall -g -fopenmp -O2 -g -MT cxalloc.lo -MD -MP -MF .deps/cxalloc.Tpo -c -o cxalloc.lo cxalloc.cpp
> g++ -DHAVE_CONFIG_H -I. -I../.. -I. -I../../cxcore/include -I../.. -DNDEBUG -fno-strict-aliasing -Wall -g -fopenmp -O2 -g -MT cxalloc.lo -MD -MP -MF .deps/cxalloc.Tpo -c cxalloc.cpp -fPIC -DPIC -o .libs/cxalloc.o
> In file included from _cxcore.h:60,
> from cxalloc.cpp:42:
> ../../cxcore/include/cxmisc.h:133:6: error: #elif with no expression
> make[4]: *** [cxalloc.lo] Error 1
> make[4]: Leaving directory `/build/tbm/opencv-1.0.0/cxcore/src‘
> make[3]: *** [all-recursive] Error 1

解决方法:

解决办法:

--- cxcore/include/cxmisc.h~ 2008-11-07 15:12:58.000000000 +0000 (删除)
+++ cxcore/include/cxmisc.h 2008-11-07 15:13:03.000000000 +0000 (打开)
@@ -130,7 +130,7 @@
#include <alloca.h>
#elif defined HAVE_ALLOCA
#include <stdlib.h>
-#elif
+#else
#error
#endif

以上的意思就是:把 该文件的#elif 改为 #else后编译成功!!!

第六步:执行./configure,make

#./configure

#make

提示以下错误:

g++ -Wall -fno-rtti -pipe -O3 -fomit-frame-pointer -o .libs/opencv-haartraining haartraining.o libcvhaartraining.a ../../../otherlibs/highgui/.libs/libhighgui.so /home/genie/Downloads/opencv-1.0.0/cv/src/.libs/libcv.so ../../../cv/src/.libs/libcv.so /home/genie/Downloads/opencv-1.0.0/cxcore/src/.libs/libcxcore.so ../../../cxcore/src/.libs/libcxcore.so -lpthread -ldl -lm
../../../otherlibs/highgui/.libs/libhighgui.so: undefined reference to `cvCaptureFromCAM_V4L(int)‘
collect2: error: ld returned 1 exit status
make[4]: *** [opencv-haartraining] Error 1
make[4]: Leaving directory `/home/genie/Downloads/opencv-1.0.0/apps/haartraining/src‘
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/genie/Downloads/opencv-1.0.0/apps/haartraining‘
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/genie/Downloads/opencv-1.0.0/apps‘
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/genie/Downloads/opencv-1.0.0‘
make: *** [all] Error 2

解决方法:https://code.ros.org/trac/opencv/changeset/5206,可能会有的部分文件目录不同,但内容相同

解决方法:https://code.ros.org/trac/opencv/changeset/5206,可能会有的部分文件目录不同,但内容相同

Unmodified:other
Added:green part
Removed:red part

TabularUnified branches/2.2/opencv/cnconfig.h.cmake

旧行号   新行号
19       19 /*V4L2 capturing support */
20   20 #cmakedefine HAVE_CAMV4L2
    21
    22 /* V4L/V4L2 capturing support via libv4l */
    23 #cmakedefine HAVE_LIBV4L
21   24
22   25 /* Carbon windowing environment */

TabularUnified branches/2.2/opencv/modules/highgui/src/cap.cpp
172   172     return capture;
173   173 #endif
174        #if defined (HAVE_CAMV4L)||defined (HAVE_CAMV4L2)
     174 #if defined HAVE_LIBV4L || (defined (HAVE_CAMV4L) && defined (HAVE_CAMV4L2))   
175   175 capture = cvCreateCameraCapture_V4L(index);
176   176 if(capture)

TabularUnified branches/2.2/opencv/modules/highgui/src/cap_libv4l.cpp
225   225 #include "precomp.hpp"
226   226
227     #if !defined WIN32 && defined HAVE_CAMV4L && defined HAVE_CAMV4L2
    227 #if !defined WIN32 && defined HAVE_LIBV4L
228 228
229 229 #defined CLEAR(x) memset(&(x), 0, sizeof(x))
.... ...
242 242 #include <sys/ioctl.h>
243 243
   244 #ifdef HAVE_CAMV4L
244 245 #include <linux/videodev.h>
   246 #endif
   247 #ifdef HAVE_CAMV4L2
245 248 #include <linux/videodev2.h>
  249 #endif
246 250
247 251 #include <libv4l1.h>

第7步:添加库
先做系统更新

#apt-get update

#apt-get upgrade

再执行

#apt-cache search opencv

后显示如下信息

libcv-dev - Translation package for libcv-dev
libcv2.3 - computer vision library - libcv* translation package
libcvaux-dev - Translation package for libcvaux-dev
libcvaux2.3 - computer vision library - libcvaux translation package
libhighgui-dev - Translation package for libhighgui-dev
libhighgui2.3 - computer vision library - libhighgui translation package
libopencv-calib3d-dev - development files for libopencv-calib3d
libopencv-calib3d2.3 - computer vision Camera Calibration library
libopencv-contrib-dev - development files for libopencv-contrib
libopencv-contrib2.3 - computer vision contrib library
libopencv-core-dev - development files for libopencv-core
libopencv-core2.3 - computer vision core library
libopencv-dev - development files for opencv
libopencv-features2d-dev - development files for libopencv-features2d
libopencv-features2d2.3 - computer vision Feature Detection and Descriptor Extraction library
libopencv-flann-dev - development files for libopencv-flann
libopencv-flann2.3 - computer vision Clustering and Search in Multi-Dimensional spaces library
libopencv-gpu-dev - development files for libopencv-gpu
libopencv-gpu2.3 - computer vision GPU Processing library
libopencv-highgui-dev - development files for libopencv-highgui
libopencv-highgui2.3 - computer vision High-level GUI and Media I/O library
libopencv-imgproc-dev - development files for libopencv-imgproc
libopencv-imgproc2.3 - computer vision Image Processing library
libopencv-legacy-dev - development files for libopencv-legacy
libopencv-legacy2.3 - computer vision legacy library
libopencv-ml-dev - development files for libopencv-ml
libopencv-ml2.3 - computer vision Machine Learning library
libopencv-objdetect-dev - development files for libopencv-objdetect
libopencv-objdetect2.3 - computer vision Object Detection library
libopencv-video-dev - development files for libopencv-video
libopencv-video2.3 - computer vision Video analysis library
opencv-doc - OpenCV documentation and examples
python-opencv - Python bindings for the computer vision library

再执行:以下命令,根据你自己上面的list做出相应替换,可能有些库会用不到,但为了防止以后出问题,我就全装了。

#apt-get install libcvaux-dev libcvaux2.3 libhighgui-dev libhighgui2.3 libopencv-calib3d-dev libopencv-calib3d2.3 libopencv-contrib-dev libopencv-contrib2.3 libopencv-core-dev libopencv-core2.3 libopencv-dev libopencv-features2d-dev libopencv-features2d2.3 libopencv-flann-dev libopencv-flann2.3 libopencv-gpu-dev libopencv-gpu2.3 libopencv-highgui-dev libopencv-highgui2.3 libopencv-imgproc-dev libopencv-imgproc2.3 libopencv-legacy-dev libopencv-legacy2.3 libopencv-ml-dev libopencv-ml2.3 libopencv-objdetect-dev libopencv-objdetect2.3 libopencv-video-dev libopencv-video2.3 opencv-doc python-opencv

第8步:重新执行./configure和make

#./configure

#make

第9步:我当时基本就没有Error了,然后执行make install,如果你们有错误,欢迎评论告知

第10步:更新动态链接库

#vim /etc/ld.so.conf

在最后一行添加:/usr/local/lib到文件中

执行以下命令:

#ldconfig

至此:安装结束。

验证安装是否成功:

进入到sample/c下

通过

#ls

可以看到有drawing.c这个文件

执行如下命令

# g++ drawing.c -o drawing `pkg-config --cflags --libs opencv`

执行./drawing

会提示错误:OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support.

原因:简单的解释就是你的GTK+ 2.x要先于OpenCV安装

所以,重新安装gtk+ 2.x,然后重执行

#./configure

#make,

#make install

#make check(检查是否安装全部正确)

再用验证阶段的g++编译,

再执行

#./drawing

就出现了动画效果了。

感谢以下链接及文献,帮我解决了很多问题:

https://code.ros.org/trac/opencv/changeset/5206

http://blog.csdn.net/loveaborn/article/details/7647734

http://www.raben.com/content/opencv-installation-ubuntu-1204

http://opencv.wikispaces.com/1)+Installation+on+Linux

http://blog.163.com/dingmz_frcmyblog/blog/static/217304023201321310532566/

http://bbs.ednchina.com/BLOG_ARTICLE_277614.HTM

http://www.arm9home.net/read.php?tid-15163.html

http://www.arm9home.net/simple/index.php?t15163.html

http://www.arm9home.net/read.php?tid-80418.html

http://www.arm9home.net/read.php?tid-8386.html

《OpenCV教程基础篇》

www.google.com.hk

www.baidu.com

Linux下配置OpenCV1.0环境,布布扣,bubuko.com

时间: 11-13

Linux下配置OpenCV1.0环境的相关文章

linux下配置LAMP开发环境,以及常用小细节

本来安装没什么可说到.但是在linux当中容易会出现各种各样到问题.我安装以后导致各种问题 比如php无法正常解析,数据库无法关闭,Apache无法开启等等........ 所以搞得我比较郁闷,现在把过程分享下,大家不要在走弯路 最后按照这个顺序来装,避免出问题 [plain] view plaincopy sudo apt-get install mysql-server-5.0 sudo apt-get install apache2 sudo apt-get install php5 li

Linux下配置PHP开发环境

转载于: http://www.uxtribe.com/php/405.html 该站下有系列PHP文章. 在Linux下搭建PHP环境比Windows下要复杂得多.除了安装Apache,PHP等软件外,还要安装一些相关工具,设置必要参数.而且,如果要使用PHP扩展库,还要进行编译.安装之前要准备如下安装包: http-2.2.8.tar.gz.下载地址:http://www.apache.org. php-5.2.5.tar.gz.下载地址:http://www.php.net/downloa

vs2013下配置opencv1.0.0

vs2013下配置opencv1.0.0 2019-4-25 17:13:13 原因 现在最新opencv已经到4.0.1版了.用opencv1.0原因: 小.源码包只有10M左右. 清晰.他的文档结构清晰,不像OpenCV2时代开始越来越多的东西加进来但是文档也越来越多看不完.. 很少有C++.比如没有Mat.因为希望在自己的项目中用纯C,即便用opencv也是用IplImage读取. 打开工程 opencv_100/_make/opencv.sln,用vs2013打开它,选择升级项目. 编译

阿里云linux下配置php服务器环境,及遇到的问题解决方法

服务器的镜像我们是选择了第三方配置好的Centos 6.3 64 位 Apache2+php5.2+Mysql5+vsftpd ,所以一键安装镜像后php环境基本就有了,所以以下是除去安装lamp之外的配置. 1.首先是配置虚拟站点,我们的服务器虚拟站点配置文件在/usr/local/apache/conf/extra/httpd-vhosts.conf ,以前用过vim但是早就忘了,所以安装了nano,还带有提示,nano的安装命 yum -y install nano  安装完成后用命令na

在Linux下配置jdk的环境变量

jdk下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 在根目录新建software目录 将下载好的jdk上传到software文件夹里面 (使用WinSCP可以非常便捷的将windows下的文件通过拖拽的方式拖入到Linux中.) 去到software这个目录 输入命令: cd /software 输入命令:ll 就可以看到我们的jdk包了 三,解压文件 解压命令

Linux下配置安装PHP环境(Apache2)

http://www.cnblogs.com/lufangtao/archive/2012/12/30/2839679.html 参考别人的做法,遇到问题上网查,下面就是安装步骤. 一.安装Apache2.2.221.到官网下载  http://httpd.apache.org/download.cgi    2.解压    tar  -zxvf httpd-2.2.22.tar.gz3.建立目标文件夹(注意以下所有操作都时在root用户下执行的)    mkdir /usr/local/apa

linux 下配置java开发环境

JDK下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 根据Linux系统的版本选择64位或32位下载,官方现提供rpm和tar.gz两种版本下载. 安装: [[email protected] cdrom]# rpm -ivh jdk-8u25-linux-x64.rpm 配置jdk环境变量 方法一:在Shell下设置变量(该方法只对当前的shell有效,如果打开另

Linux下配置java的环境变量,So Easy!!

首先,在cd /usr ,mkdir java. 将java安装包放到/usr/java,并解压. 验证java. $ java -version 如果提示有如下安装包包含它,但是没有安装.是环境变量没有配置的原因. (可以进入java解压包里面验证,可行就表示java包没有问题!) 配置环境变量,vi /etc/profile 在任意位置添加如下代码 #Set java environmentexport PATH=$PATH:/usr/java/jdk1.8.0_25/bin export

linux下配置redis4.0.2主从复制以及高可用

一.环境 三台服务器分别为: 172.28.18.75/172.28.18.103/172.28.18.104 在三台服务器上分别部署一个redis节点以及一个sentinel节点 二.主从复制配置 1.172.28.18.75为主redis配置在25700端口 vim /etc/redis/redis-25700.conf 主要配置项如下: bind 172.28.18.75 port 25700 #从节点访问主节点的密码masterauth "password" #redis客户端