CentOS系統上編譯、安裝、配置OpenCV

來源:互聯網
上載者:User

標籤:

聲明:本文是個人根據相關部落格資料加上自己的經驗整理,在此分享以供大家學習交流!

假設CentOS系統下的CodeBlocks已經安裝完成,下面我們要在CentOS平台下編譯OpenCV,並在CodeBlocks下進行開發測試。

(1)下載OpenCV源碼,並編譯安裝

當前最新的版本是OpenCV-2.2,可以從http://sourceforge.net/projects/opencvlibrary/上下載。

OpenCV的編譯方式有兩種,一種是傳統的./configure ; make ; make install,這種方式適用於OpenCV-1.0,相應的編譯過程可以參見這篇文章:http://www.opencv.org.cn/index.php/%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91,另一種方式是使用cmake . ; make ; make install,這種方式適用於OpenCV-2.x。所以,在編譯OpenCV-2.2之前,得先在CentOS上安裝CMake(http://www.cmake.org/)。

(1.1) 編譯安裝cmake:

假設cmake-2.8.4.tar.gz放在/root/software/cmake-2.8.4.tar.gz

cd /root/software/

tar zxvf cmake-2.8.4.tar.gz

編譯安裝cmake

下載cmake源碼包cmake-2.8.4.tar.gz,mv到/usr/local/src目錄下

[[email protected] ~]# cd /usr/local/src/  

[[email protected] src]# tar xzvf cmake-2.8.7.tar.gz   

[[email protected] src]# cd cmake-2.8.7 

[[email protected] cmake-2.8.4]# ./bootstrap   

---------------------------------------------  

CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.  

---------------------------------------------  

Error when bootstrapping CMake:  

Cannot find appropriate C compiler on this system.  

Please specify one using environment variable CC.  

See cmake_bootstrap.log for compilers attempted.  

---------------------------------------------  

Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log  

---------------------------------------------  

報錯:缺少C的編譯器。

安裝gcc編譯器

可以從Linux系統的安裝盤中安裝,也可以簡單地用yum安裝

[[email protected] ~]# yum install gcc  

繼續cmake的安裝

[[email protected] cmake-2.8.4]# ./bootstrap   

---------------------------------------------  

CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.  

C compiler on this system is: cc   

---------------------------------------------  

Error when bootstrapping CMake:  

Cannot find appropriate C++ compiler on this system.  

Please specify one using environment variable CXX.  

See cmake_bootstrap.log for compilers attempted.  

---------------------------------------------  

Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log  

---------------------------------------------  

再次報錯:缺少C++編譯器。

安裝gcc-c++編譯器

同樣可以從Linux系統的安裝盤中安裝,或者簡單地用yum安裝

[[email protected] ~]# yum install gcc-c++  

重複上面的操作

[[email protected] cmake-2.8.4]# ./bootstrap

沒有報錯後,編譯安裝

[[email protected] cmake-2.8.4]# gmake  

[[email protected] cmake-2.8.4]# gmake install  

(1.2)編譯安裝opencv-2.2:(注意:若需要圖形庫,要先安裝gtk2.x)

假設OpenCV-2.2.0.tar.bz2放在/root/software/ OpenCV-2.2.0.tar.bz2

cd /root/software/

tar jxvf OpenCV-2.2.0.tar.bz2

cd OpenCV-2.2.0

mkdir release

cd release

cmake ../

make

make install

錯誤及解決:http://gaodr.blog.163.com/blog/static/10461500820134824949883/

1) Linking CXX executable ../../bin/opencv_perf_core
../../lib/libopencv_highgui.so.2.4.9: undefined reference to `[email protected]_0‘

解決方案:修改/opt/opencv2.3.1目錄下的CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原來為空白,加上-lpng,如:

萬一還是不行的話,就用locate libpng查看一下,然後逐個按路徑刪除與libpng相關的所有東西,重新安裝libpng庫。

yum remove libpng

yum install libpng

yum install libpng-devel

編譯freak.cpp時出現問題:
錯誤:在類 ‘GENERAL_REGS’ 中找不到可捨出的寄存器
經查,與編譯最佳化參數有關,找到編譯freak.cpp的編譯控制檔案
flags.make與link.txt,將
編譯最佳化選項從
-O3 改為
-O0
該錯誤解決。

出現錯誤:類似c++: Internal error: Killed (program cc1plus)

解決方案:cmake是用如下命令

cmake ../  -DCMAKE_C_FLAGS_RELEASE="-O1 -DNDEBUG" -DCMAKE_CXX_FLAGS_RELEASE="-O1 -DNDEBUG"
b)錯誤:
Linking CXX executable ../../bin/opencv_perf_core
../../lib/libopencv_highgui.so.2.4.5: undefined reference to `png_set_longjmp_fn‘
collect2: ld 返回 1
make[2]: *** [bin/opencv_perf_core] 錯誤 1
make[1]: *** [modules/core/CMakeFiles/opencv_perf_core.dir/all] 錯誤 2
經查,與編譯libopencv_highgui.so.2.4.5時參數有關,修改控制編譯libopencv_highgui.so.2.4.5的檔案link.txt
再修改編譯pencv_perf_core的檔案link.txt.
都增加或改為:-lpng  /usr/local/lib/libpng16.so
該錯誤解決。
原因:系統中libpng.so庫有不同版本,指定使用libpng16.so

(1.3)設定環境變數

這一步與Windows設定系統內容變數的目的是一樣的,告訴系統相應的binary files和library files在什麼位置。

cd /etc/ld.so.conf.d/

vim opencv.conf

將/usr/local/lib寫入檔案並儲存

ldconfig

可以使用locate libcv查看一下相應庫檔案的位置。

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

(2)配置OpenCV

參見http://blog.csdn.net/dupei/archive/2011/05/18/6428283.aspx

配置完成以後,就可以使用測試案例進行測試了。如果順利執行起來,說明OpenCV的配置已經完成。

最後一步,測試openCV庫是否可用。

$ cd ~/openCV/samples/cpp

$ gcc -I/usr/local/include/opencv -L/usr/local/lib/ -lopencv_highgui -lstdc++ drawing.cpp -o drawing

$ ./drawing

報錯:OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /home/armmlinux/zdfwork/project/software/opencv-2.4.9/modules/highgui/src/window.cpp, line 483

解決:安裝gtk2.x

http://www.jb51.net/article/22134.htm

Glib安裝提示gettext問題的解決方案:http://blog.csdn.net/ybdesire/article/details/7249896

安裝libffi庫:http://download.chinaunix.net/download/0006000/5819.shtml

編譯glib庫是報類似libgettext.so等的錯誤:http://blog.csdn.net/david_xtd/article/details/7625626

明明安裝了庫,還出現類似:configure: error: Library requirements (glib-2.0 >= 2.4.0 atk >= 1.0.1 pango >= 1.4.0) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them. 的錯誤:http://blog.csdn.net/ubuntulover/article/details/6978305

CentOS系統上編譯、安裝、配置OpenCV

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.