opencv2.2 交叉编译 及在arm开发板测试

环境:arm开发板是 ok6410,主机是Ubuntu10.04

1,准备工作:交叉编译工具用光盘自带的arm-linux-4.4.1.tar.gz,解压到/usr/local/arm目录下(将/usr/local/arm/bin加入环境变量);下载opencv2.2的源码;安装cmake build-essential;安装必要的库:  libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev libjpeg62-dev libtiff4-dev  libjasper-dev

2,用到的主要目录说明:
交叉编译工具链所在  /usr/local/arm
编译好的opencv库所在  /usr/local/opencv-arm
安装opencv的目录     /usr/local/arm-linux
opencv源码所在      ~/tiaozhansai/OpenCV-2.2.0

3,在终端运行sudo cmake-gui  
    选择源代码目录:/home/xin/tiaozhansai/OpenCV-2.2.0
      选择Build目录:/usr/local/opencv-arm/
       点击Configure,保持generator为Unix Makefiles,选择Specify options for cross-compiling,点击Next,
       Operating System填写arm-linux
       C Compilers填写/usr/local/arm/4.4.1/bin/arm-linux-gcc
       C++ Compilers填写/usr/local/arm/4.4.1/bin/arm-linux-g++
       程序库的Target Root填写/usr/local/arm/4.4.1/
然后点击Finish。
修改默认配置,默认安装目录为/usr/local,为便于查找生成的库文件,把CMAKE_INSTALL_PREFIX变量改为/usr/local/arm-linux  ,点击Generate生成Makefile。

4,在/usr/local/opencv-arm目录下$sudo make
(1),80%报错:
。。。。/home/xin/tiaozhansai/OpenCV-2.2.0/modules/ml/src/gbt.cpp:474: error: 'expl' was not declared in this scope

    修改gbt.cpp中14行,16行:注释掉

                    //#if ANDROID

                    #define expl(x) exp(x)
                    //#endif
        错误消除。

(2),83%报错:
Linking CXX executable ../../bin/opencv_createsamples
../../lib/libopencv_core.so: undefined reference to `clock_gettime'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFerrorHandler'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFrealloc'
../../lib/libopencv_core.so: undefined reference to `pthread_key_create
    解决方法:修改CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原来为空,加上-lpthread -lrt,重新编译,错误消除

(3),83%报错:
Linking CXX executable ../../bin/opencv_createsamples
../../lib/libopencv_highgui.so: undefined reference to `_TIFFerrorHandler'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFrealloc'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFmalloc'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFmemcpy'
../../lib/libopencv_highgui.so: undefined reference to `TIFFOpen'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFfree'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFwarningHandler'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFmemcmp'
../../lib/libopencv_highgui.so: undefined reference to `_TIFFmemset'
    解决方法:修改CMakeCache.txt,WITH_TIFF:BOOL=ON,改成OFF(不再对TIFF图像格式支持。这里我前面已经装过libtiff4-dev,但是编译报错,我不明白是为什么),重新编译,错误消除。

(4),96%报错:
CMakeFiles/opencv_test.dir/src/highguitest.obj: In function `CV_HighGuiTest::run(int)':
highguitest.cpp:(.text._ZN14CV_HighGuiTest3runEi+0x18): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
../../lib/libopencv_features2d.so: undefined reference to `cv::SIFT::SIFT(double, bool, bool, int, int, int, int)'
    解决方法:在OpenCV2.2.0/modules/features2d/src/sift.cpp下
            #ifdef __arm__
            #define ARM_NO_SIFT
            #endif   
        注释掉#define ARM_NO_SIFT.错误消除,
成功!

$sudo make install

5,opencv库复制到ok6410,并测试
(1)借用某个博客上的测试程序,来测试编译的是否成功。
新建test.cpp:
    // test.cpp  
      
    #include <cv.h>  
    #include <cxcore.h>  
    #include <highgui.h>  
      
      
    int main()  
    {  
            CvCapture* capture = NULL;  
            IplImage* frame = NULL;  
      
            if( !(capture = cvCaptureFromCAM(-1)))  
            {  
                    fprintf(stderr, "Can not open camera./n");  
                    return -1;  
            }  
      
            cvNamedWindow("video", 1);  
      
            while(frame = cvQueryFrame( capture ) )  
            {  
                    cvShowImage("video", frame);  
            }  
      
            cvDestroyWindow("video");  
            cvReleaseCapture(&capture);  
            return 0;  
    }  

编译test.cpp:$ arm-linux-g++ -I/usr/local/arm-linux/include/opencv/ -L/usr/local/arm-linux/lib/ -lcv -lcxcore -lhighgui -lpthread -lrt -o test test.cpp
报错:/usr/local/arm/4.4.1/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lcv

google之,发现这个问题是找不到libcv.so这个动态库。
通过find命令发现在/usr/local/arm-linux/lib/下面确实没有这个库,而且这个目录下的库都是libopencv*形式的,我猜测是不是opencv2.2相比2.1作了不少改动,网上调研发现确实时这样的,opencv2.2重新组织库结构,用较详细,更小的模块来取代cxcore, cv, cvaux, highgui 和 ml库.
于是,试着把命令改成:$ arm-linux-g++ -I/usr/local/arm-linux/include/opencv/ -L/usr/local/arm-linux/lib/ -lopencv_core  -lopencv_highgui -lpthread -lrt -o test test.cpp
结果还是报上面的错误,这次我注意到它是在。。。/arm-none-linux-gnueabi/。。这个目录下找动态库的,也就是说,尽管我指定了头文件,库文件的搜索路径,但是它没有去我指定的路径下找。于是我把/usr/local/opencv-arm/include/opencv/下的头文件和/usr/local/opencv-arm/lib下的动态库全都拷贝到/usr/local/arm/4.4.1/arm-none-linux-gnueabi下面对应的目录下,然后再编译:
$ arm-linux-g++ -lopencv_core -lopencv_highgui -lpthread -lrt -o test test.cpp

成功!

(2)将库文件s 和 编译好的测试程序test 拷贝到开发板测试
用sd卡拷贝,遇到问题:
cp: cannot create '../../lib/libopencv_calib3d.so': Read-only file system       
cp: cannot create '../../lib/libopencv_contrib.so': Read-only file system       
cp: cannot create '../../lib/libopencv_core.so': Read-only file system  

这个跟cramfs文件系统是只读的文件系统相关,烧写yaffs文件系统即可解决这个问题。  

评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值