Linux下配置OpenCV1.0環境

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   os   檔案   io   

自己一直嚷嚷著打算學學Image Recognition,識別個簡單的,車牌號,驗證碼之類的,之前查過資料,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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.