首页 > 代码库 > DM8168 OpenCV尝试与评估(编译ARM版OpenCV)
DM8168 OpenCV尝试与评估(编译ARM版OpenCV)
交叉编译opencv2.3.1,并在DM8168 cortex A8中执行图像处理。
开发环境:
PC:ubuntu12.04LTS。Intel Core 2 Duo CPU E7200@2.53GHZ;
目标平台:SEED DVS DM8168 DVRRDK 02.00.XXXX
第一篇:OpenCV交叉编译
參考了http://blog.csdn.net/embeddedman/article/details/7416934
1.安装交叉编译链
使用DVRRDK中的ti_tools/cgt_a8/arm-2009q1/bin/arm-none-linux-xxx
需将其增加环境变量:能够加到用户文件夹下的.bashrc或/etc/profile
格式例如以下:
export PATH=/...../bin:$PATH
2.获得OpenCV源代码,本文基于2.3.1
3.安装cmake cmake-gui
4.建立编译文件夹如/opencv231/build_arm
5.进入文件夹运行cmake-gui
选择源码文件夹:/opt/OpenCV-2.31
选择Build文件夹:/opt/opencv2.3.1_forArm,大家依据自己的喜好设置编译文件夹吧。
点击Configure,保持generator为Unix Makefiles。选择Specify options for cross-compiling,点击Next
Operating System填写arm-inux
C Compilers选择DVRRDK_02.00.00.23/ti_tools/cgt_a8/arm-2009q1/bin/arm-none-linux-gnueabi-gcc
C++ Compilers填写.......-g++
程序库的Target Root填写OpenCV安装文件夹,然后点击Finish
上面标注的表示opencv将要安装的文件夹,默觉得/usr/local,为了便于管理,大家能够安装在自己设定的文件夹下,能够改动,同一时候。网上资料说:另外,我没有安装tiff图像的支持,因此去掉WITH_TIFF(出自:http://blog.csdn.net/eagelangel/article/details/7232364)。在此点击Configure,然后点击Gennerate就会生成Makefile。
进入/opt/opencv2.3.1_forArm文件夹。运行make命令,就会编译opencv,编译过程中遇到例如以下错误:
In file included from /opt/OpenCV-2.3.1/modules/flann/src/precomp.hpp:9,
from /opt/opencv2.3.1_forArm/modules/flann/opencv_flann_pch_dephelp.cxx:1:
/opt/OpenCV-2.3.1/modules/flann/include/opencv2/flann/dist.h: In function ‘T cvflann::abs(T) [with T = long double]‘:
/opt/OpenCV-2.3.1/modules/flann/include/opencv2/flann/dist.h:63: error: ‘fabsl‘ was not declared in this scope
make[2]: *** [modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/opencv_flann_pch_dephelp.obj] Error 1
make[1]: *** [modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/all] Error 2
make: *** [all] Error 2
解决方法:改动OpenCV-2.3.1/modules/flann/include/opencv2/flann/dist.h文件第63行的源代码:将absl()改动为abs()
假设编译过程遇到例如以下错误:
Linking CXX executable ../../bin/opencv_test_calib3d
../../lib/libopencv_core.so: undefined reference to `pthread_key_create‘
../../lib/libopencv_core.so: undefined reference to `pthread_getspecific‘
../../lib/libopencv_ts.so: undefined reference to `pthread_key_delete‘
../../lib/libopencv_core.so: undefined reference to `pthread_once‘
../../lib/libopencv_core.so: undefined reference to `clock_gettime‘
../../lib/libopencv_core.so: undefined reference to `pthread_setspecific‘
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_test_calib3d] Error 1
make[1]: *** [modules/calib3d/CMakeFiles/opencv_test_calib3d.dir/all] Error 2
make: *** [all] Error 2
解决方式:改动/opt/opencv2.3.1文件夹下的CMakeCache.txt。CMAKE_EXE_LINKER_FLAGS原来为空。加上-lpthread -lrt,假设没有自己加上。
注意:每次错误产生。经改动后。仅仅要再次运行make命令就接着编译,编译成功后,运行make intall命令就会安装opencv。
因为本人的安装文件夹为:/opt/opencv2.3.1_arm,大家能够看到生成了bin、lib、include等文件夹,例如以下:
第二篇
执行
1.将以上文件夹lib include是必须的拷贝的板子上。文件夹能够随意,也能够放到系统动态库文件夹。关于这两点能够參考:
http://blog.chinaunix.net/uid-23215128-id-2521319.html
一个演示样例代码:
#include "cv.h" #include "highgui.h" int main( int argc, char** argv ) { IplImage* pImg; //声明IplImage指针 //加载图像。强制转化为Gray if( argc == 3 && (pImg = cvLoadImage( argv[1], 0)) != 0 ) { IplImage* pImg2 = cvCreateImage(cvGetSize(pImg), pImg->depth, pImg->nChannels); cvCopy(pImg, pImg2, NULL); cvSaveImage(argv[2], pImg2);//把图像写入文件 cvReleaseImage( &pImg ); //释放图像 cvReleaseImage( &pImg2 ); //释放图像 return 0; } return -1; }
採用下面命令方式在pc上进行编译,当然编译时所连接的库是arm版的:
arm-none-linux-gnueabi-g++ test.cpp -o main1 -I/usr/local/arm/opencv/include/opencv -I/usr/local/arm/opencv/include -L/usr/local/arm/opencv/lib -lpthread -ldl -lrt -lopencv_core -lopencv_highgui
(文件夹可能有所不同)
假设PC中 arm的库的路径与lib在板子上的路径不一致的话,运行程序会提示找不到库,这时能够通过板卡设置export LD_LIBRARY_PATH= 使程序能够搜索到库。
另外最好将板子上opencvlib的文件夹见一个软连接到/usr/lib.
2.运行
./
结论:
终于执行结果:cvSplit cvMin cvCreateImage等等的操作,大概是台式机PC的1/40的速度。
计划:与DSP联合运算。
DM8168 OpenCV尝试与评估(编译ARM版OpenCV)