OpenCV在ARM上的移植


與X86 Linux類似,請參考: Linux 下編譯安裝OpenCV 本文在此基礎上進行進一步操作。

網絡上很多移植編譯的方法比較老,多數針對OpenCV 1.0,而且方法很麻煩,不仔細操作很容易出錯,我的方法是盡可能的利用現成的工具,盡量圖形化界面配置操作,方便編譯配置。

軟硬件環境

宿主機:Ubuntu 12.04 32bit

開發板:OK6410

OpenCV: 2.4.3

其他:

arm-linux-g++ 4.3.2 / arm-linux-gcc 4.3.2

CMake-gui 2.8.10

Cmake的安裝

OpenCV 2.2以后版本需要使用Cmake生成makefile文件,因此需要先安裝cmake。

ubuntu下安裝cmake比較簡單,

apt-get install cmake

如果覺得自帶的版本不符合要求,可以下載安裝包。

下載最新版的安裝包:

http://www.cmake.org/cmake/resources/software.html

這里下載已經編譯好的,這樣只需要解壓至需要的目錄下即可使用:

tar zxvf cmake-2.8.10.2-Linux-i386.tar.gz –C /usr/local/

設置環境變量:

sudo gedit /home/emouse/.bashrc

在打開的文件后添加:

export PATH=$PATH:/usr/local/cmake-2.8.10.2-Linux-i386/bin

查看版本,測試是否安裝成功:

root@emouse:/home# cmake --version
cmake version 2.8.10.2

轉載注明:http://emouse.cnblogs.com/ 

OpenCV 的交叉編譯

解壓OpenCV壓縮文件,得到文件夾。

#cmake-gui 打開cmake的gui界面,開始進行配置,配置過程如下圖所示:

1、選定解壓后的源文件和將要編譯的文件目錄,這個自己之前先建好。

2、點擊Configure 選擇工程類型,選擇交叉編譯,點擊下一步。

image

3、在下圖的界面中選擇交叉編譯工具鏈以及庫文件相關信息,按照圖中的進行填寫,其中紅框部分為交叉編譯工具鏈的實際路徑,根據宿主機實際安裝路徑填寫。

image

4、點擊Finsh完成初步配置。

5、此時主界面如下圖所示,這時Cmake會讀取程序的一些配置信息,可以再下圖紅框中對每一個編譯選項進行修改,這里去掉WITH_TIFF支持並修改安裝路徑,其他配置可以根據需求選擇。

image

通過終端進入OpenCV-ARM目錄,make編譯,編譯過程中出錯如下:

Linking CXX executable ../../bin/opencv_perf_core
../../lib/libopencv_highgui.so: undefined reference to `_TIFFmemcpy'
../../lib/libopencv_core.so: undefined reference to `pthread_spin_init'
../../lib/libopencv_core.so: undefined reference to `pthread_spin_unlock'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFmemset'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFwarningHandler'
../../lib/libopencv_core.so: undefined reference to `pthread_key_create'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFmemcmp'
../../lib/libopencv_core.so: undefined reference to `pthread_getspecific'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFfree'
../../lib/libopencv_ts.so: undefined reference to `pthread_key_delete'
../../lib/libopencv_core.so: undefined reference to `pthread_spin_lock'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFmalloc'
../../lib/libopencv_highgui.so: undefined reference to `TIFFOpen'
../../lib/libopencv_core.so: undefined reference to `pthread_spin_destroy'
../../lib/libopencv_core.so: undefined reference to `pthread_once'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFrealloc'
../../lib/libopencv_core.so: undefined reference to `clock_gettime'
../../lib/libopencv_core.so: undefined reference to `pthread_spin_trylock'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFerrorHandler'
../../lib/libopencv_core.so: undefined reference to `pthread_setspecific'
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_perf_core] 錯誤 1
make[1]: *** [modules/core/CMakeFiles/opencv_perf_core.dir/all] 錯誤 2
make: *** [all] 錯誤 2

關於TIFF的報錯,是因為一開始我勾選了TIFF的支持,而這個支持是需要宿主機中安裝相應的程序的,所以報錯,可以打開cmake 去掉勾選。 其他報錯經過查找找到以下解釋:

編譯時發現如下錯誤:
Linking CXX executable ../../bin/opencv_createsamples
../../lib/libcxcore.so: undefined reference to `clock_gettime'
../../lib/libcxcore.so: undefined reference to `pthread_key_create'
../../lib/libcxcore.so: undefined reference to `pthread_getspecific'
../../lib/libcxcore.so: undefined reference to `pthread_setspecific'

原因是cmake不認識我定義的arm-linux系統標記,沒有加上庫pthread和rt的鏈接選項

此時需要修改CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原來為空,加上-lpthread -lrt

按照此方法更改對應文件,如下圖所示:

image

此處在CMakeCache.txt 的173行,添加-lpthread -lrt,然后繼續編譯。編譯過程十來分鍾左右,編譯成功結果如下:

image

運行make install進行安裝,在我的安裝目錄中就會多出以下幾個文件夾:

image 

lib文件夾即生成的庫文件,拷貝到開發板對應目錄即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM