此次測試使用軟體版本如下
- Ubuntu 14.04 32bit
- OpenCV 3.0.0
- ARM 2013 05 (gcc 4.7.3)
步驟如下
1. 安裝 arm tool chain
$ wget http://files.virt2real.ru/soft/codesourcery/arm-2013.05.tar.gz
$ tar zxvz arm-2013.05.tar.gz
$ sudo mv arm-2013.05 /usr/local/
$ vi ~/.bashrc
add below line$ source ~/.bashrc
export PATH=$PATH:/usr/local/arm-2013.05/bin
2. 安裝 cmake
$ sudo apt-get install cmake-qt-gui
3. 下載 OpenCV,並預先建立編譯目錄
$ wget https://github.com/Itseez/opencv/archive/3.0.0.zip
$ unzip 3.0.0.zip
$ cd opencv-3.0.0
$ sudo mkdir -p /usr/local/arm-opencv
4. 設定編譯選項,並產生 Makefile
$ sudo cmake-gui按下 Configure
選擇 Next
填入 arm toolchain 相關資訊如下,按下 Finish
此時出現紅字如下
選取
- BUILD_JASPER,
- BUILD_JPEG,
- BUILD_ZLLIB,
- BUILD_WITH_DEBUG_INFO,
- BUILD_opencv_world (只編譯成一個大的函數庫)
取消選取
- BUILD_DOCS,
- BUILD_PERF_TESTS
- BUILD_TESTS,
- BUILD_FAT_JAVA_LIB,
- BUIlD_openvc_app
- BUILD_SHARED_LIBS,
- WITH_CUDA
- WITH_PNG,
- WITH_TIFF,
- WITH_WEBP
- 修改 CMAKE_INSTALL_PREFIX = /usr/local/opencv
- 再按一次 Configure,此時紅色區域將會消失
還沒完哦,為了避免編譯錯誤,接著要做些進階設定,請勾選 Advanced,設定CMAKE_EXE_LINKER_FLAGS= -lpthread -ldl -lrt,
CMAKE_C_FLAGS = -DWITH_PARALLEL_PF=OFF
CMAKE_CXX_FALGS = -DWITH_PARALLEL_PF=OFF
再按一次 Configure ,接著按下 Generate
5. 開始編譯
$ cd /usr/local/arm-opencv
$ sudo make
$ sudo make install
$ sudo cp /usr/local/arm-opencv/3rdparty/lib/* /usr/local/opencv/lib/
6. 撰寫測試程式,進行測試
參考資料:
a. 測試程式舉例 (demo.cpp)
#include
using namespace cv;
using namespace std;
int main()
{
cv::Mat srcMat;
cv::Mat dstMat;
srcMat = cv::imread( "/tmp/lena.jpg" , 1); cv::cvtColor( srcMat, dstMat, CV_BGR2GRAY );
cv::imwrite( "/tmp/Gray_Image.jpg", dstMat ); return 0;
}
b. 編譯程式碼
/usr/local/arm-2013.05/bin/arm-none-linux-gnueabi-g++ demo.cpp -o demo \
-I/usr/local/arm-2013.5/arm-none-linux-gnueabi/include \
-I/usr/local/opencv/include \
-L/usr/local/opencv/lib \
-lpthread -ldl -lm -lz \
-lopencv_world \
-lzlib -llibjpeg -llibpng -lIlmImf -llibjasper -lstdc++
c. 將 demo 與 Lena.jpg 複製到 ARM 平台,便可以執行 ./demo 觀看執行成果。
$ ./demo
參考資料:
- http://blog.csdn.net/luotuo44/article/details/8958990
- http://wenku.baidu.com/view/ed89108271fe910ef12df8e7.html
- http://blog.csdn.net/wjl_hdu/article/details/8018218