Linux下配置OpenCV1.0环境

自己一直嚷嚷着打算学学图像识别,识别个简单的,车牌号,验证码之类的,之前查过资料,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 ([email protected]) (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,可能会有的部分文件目录不同,但内容相同

Unmodified:other
Added:green part
Removed:red part
  • TabularUnifiedbranches/2.2/opencv/cvconfig.h.cmake 

    r3528r5206 
    1919 /* V4L2 capturing support */ 
    2020 #cmakedefine HAVE_CAMV4L2 
     21  
     22 /* V4L/V4L2 capturing support via libv4l */ 
     23 #cmakedefine HAVE_LIBV4L 
    2124  
    2225 /* Carbon windowing environment */ 
  • TabularUnifiedbranches/2.2/opencv/modules/highgui/src/cap.cpp 

    r4313r5206 
    172172                 return capture; 
    173173         #endif 
    174          #if defined (HAVE_CAMV4L) || defined (HAVE_CAMV4L2
     174         #if defined HAVE_LIBV4L || (defined (HAVE_CAMV4L) && defined (HAVE_CAMV4L2)
    175175             capture = cvCreateCameraCapture_V4L (index); 
    176176             if (capture) 
  • TabularUnifiedbranches/2.2/opencv/modules/highgui/src/cap_libv4l.cpp 

    r3852r5206 
    225225 #include "precomp.hpp" 
    226226  
    227  #if !defined WIN32 && defined HAVE_CAMV4L && defined HAVE_CAMV4L2 
     227 #if !defined WIN32 && defined HAVE_LIBV4L 
    228228  
    229229 #define CLEAR(x) memset (&(x), 0, sizeof (x)) 
     
    242242 #include <sys/ioctl.h> 
    243243  
     244 #ifdef HAVE_CAMV4L 
    244245 #include <linux/videodev.h> 
     246 #endif 
     247 #ifdef HAVE_CAMV4L2 
    245248 #include <linux/videodev2.h> 
     249 #endif 
    246250  
    247251 #include <libv4l1.h> 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。