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

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

配置环境系统信息:Linux

catgenie@debian:~$ cat /etc/debian_version
7.6
genie@debian:~$ cat /proc/version
Linux version 3.2.0-4-amd64 (debian-kernel@lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP Debian 3.2.60-1+deb7u1
genie@debian:~$

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环境的更多相关文章

  1. Linux下配置PHP开发环境

    转载于: http://www.uxtribe.com/php/405.html 该站下有系列PHP文章. 在Linux下搭建PHP环境比Windows下要复杂得多.除了安装Apache,PHP等软件 ...

  2. vs2013下配置opencv1.0.0

    vs2013下配置opencv1.0.0 2019-4-25 17:13:13 原因 现在最新opencv已经到4.0.1版了.用opencv1.0原因: 小.源码包只有10M左右. 清晰.他的文档结 ...

  3. 4.linux下配置Golang的环境变量

    装好linux后优先在linux上配置Golang开发环境. 1.到Go语言中文网下载Linux安装包 https://studygolang.com/dl 2.到下载的目录下解压,下载的文件一般在“ ...

  4. 在Linux下配置jdk的环境变量

    jdk下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 在根目录新建s ...

  5. Linux下配置Golang开发环境

    前几天无意间看到了微信推送的golang开发的消息,看到golang那么牛逼,突然心血来潮想学习一下go.工欲善其事必先利其器,想做go开发,必须先配置好go的开发环境(就像开发Java先安装配置jd ...

  6. Linux下配置安装PHP环境

    参考别人的做法,遇到问题上网查,下面就是安装步骤. 一.安装Apache2.2.221.到官网下载  http://httpd.apache.org/download.cgi    2.解压    t ...

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

    本来安装没什么可说到.可是在linux其中easy会出现各种各样到问题. 我安装以后导致各种问题 比方php无法正常解析,数据库无法关闭,Apache无法开启等等........ 所以搞得我比較郁闷, ...

  8. Linux 下配置php开发环境

    windows下有一键安装的环境很方便,不过现实中常常服务器是linux系统.想要搭建环境怎么搞呢? 边学变发直播博客,不定期更新.

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

    首先,在cd /usr ,mkdir java. 将java安装包放到/usr/java,并解压. 验证java. $ java -version 如果提示有如下安装包包含它,但是没有安装.是环境变量 ...

随机推荐

  1. SVN里常见的图标及其含义

    - 已忽略版本控制的文件.可以通过Window → Preferences → Team → Ignored Resources.来忽略文件.A file ignored by version con ...

  2. hdu 5442 (ACM-ICPC2015长春网络赛F题)

    题意:给出一个字符串,长度是2*10^4.将它首尾相接形成环,并在环上找一个起始点顺时针或逆时针走一圈,求字典序最大的走法,如果有多个答案则找起始点最小的,若起始点也相同则选择顺时针. 分析:后缀数组 ...

  3. Android 的 AlarmManager 和 wakeLock联合使用

    http://stackoverflow.com/questions/6864712/android-alarmmanager-not-waking-phone-up 主要说的是,对于android ...

  4. eclipse 工作环境配置

    1.更换编辑颜色, http://eclipse-color-theme.github.io/update/ 下载离线安装包,解压缩 eclipse-color-theme-update-site\u ...

  5. perl的一些函数(二)

    1. tr 转换 转换不是替换(tr///==y///) tr/searchlist/replacementlist/用于查找某个一个字符串,并用replacementlist替换,可以使用正则表达式 ...

  6. java sleep() 、yield()

    1.sleep() 使当前线程(即调用该方法的线程)暂停执行一段时间,让其他线程有机会继续执行,但它并不释放对象锁.也就是说如果有synchronized同步快,其他线程仍然不能访问共享数据.注意该方 ...

  7. Effective C++ -----条款14: 在资源管理类中小心copying行为

    复制RAII对象必须一并复制它所管理的资源,所以资源的copying行为决定RAII对象的copying行为. 普遍而常见的RAII class copying行为是:抑制copying(使用私有继承 ...

  8. Spring配置数据源

    Spring在第三方依赖包中包含了两个数据源的实现类包,其一是Apache的DBCP,其二是 C3P0.可以在Spring配置文件中利用这两者中任何一个配置数据源. DBCP数据源 DBCP类包位于 ...

  9. 【XLL API 函数】 xlFree

    用于释放使用 Excel4,Excel4v,Excel12,Excel12v 分配的 XLOPER/XLOPER12 占用的内存资源. xlFree 函数释放辅助内存和重置指针为NULL但不释放XLO ...

  10. 配置TFS2010的用户截图

    先要添加一个管理用户