Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3167470
  • 博文数量: 685
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5303
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-19 14:17
个人简介

文章分类

全部博文(685)

文章存档

2015年(116)

2014年(569)

分类: 云计算

2014-09-15 13:58:03

原文地址:http://blog.chinaunix.net/uid-25885064-id-3237942.html

一、编译环境及库文件

linux环境:ubuntu-10.10
交叉编译:4.3.3
arm板子:tq2440

libz:        zlib-1.2.7
libjpeg:       jpegsrc.v7
libpng:       libpng-1.5.10
libyasm:       yasm-1.2.0
opencv:        opencv-1.0.0
libx264:       x264-snapshot-20120608-2245
libxvid:       xvidcore-1.3.2
lffmpeg:       ffmpeg-0.10.3



二、opencv-2.4.1的移植过程

1、libz的交叉编译:

#CC=arm-linux-gcc ./configure --prefix=/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi --shared
#make 
#make install

2、libjpeg的交叉编译:

#./configure --host=arm-linux --prefix=/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi --enable-shared --enable-static
#make install


3、libpng的交叉编译

#./configure --host=arm-linux --prefix=/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi --enable-shared --enable-static 
#make
#make install

4、yasm的交叉编译:

#./configure --host=arm-linux --prefix=/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi --enable-shared --enable-static 
#make
#make install


5、libx264的交叉编译:

#CC=arm-linux-gcc ./configure --enable-shared --host=arm-linux --disable-asm --prefix=/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi
#make
#make install


6、libxvid的交叉编译:

#cd build/generic
#./configure --prefix=/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi --host=arm-linux  --disable-assembly
#make
#make install

7、ffmpeg的交叉编译:

#./configure --prefix=/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi --enable-shared --disable-static --enable-gpl --enable-cross-compile --arch=arm --disable-stripping --target-os=linux --enable-libx264 --enable-libxvid --cc=arm-linux-gcc --enable-swscale
#make
#make install

8、opencv2.4.1的交叉编译:

用到的主要目录说明:
交叉编译工具链所在目录      /opt/EmbedSky/4.3.3/
安装opencv的目录         /opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/
opencv源码所在目录          /srv/sdk_tq2440/lib/OpenCV-2.4.1/
编译好的opencv库所在目录      /srv/sdk_tq2440/lib/OpenCV-2.4.1/build

#mkdir build
#cd build
#cmake-gui
选择源代码目录:/srv/sdk_tq2440/lib/OpenCV-2.4.1/
选择Build目录:/srv/sdk_tq2440/lib/OpenCV-2.4.1/build
点击Configure,保持generator为Unix Makefiles,选择Specify options for cross-compiling,点击Next,
Operating System填写arm-linux
C Compilers填写/opt/EmbedSky/4.3.3/bin/arm-linux-gcc
C++ Compilers填写/opt/EmbedSky/4.3.3/bin/arm-linux-g++
程序库的Target Root填写/opt/EmbedSky/4.3.3/
然后点击Finish。
修改默认配置,默认安装目录为/usr/local,为便于查找生成的库文件,把CMAKE_INSTALL_PREFIX变量改为/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/,点击Generate生成Makefile。

#make

错误一:

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,重新编译,错误消除

错误二:
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,重新编译,错误消除。

#make install



三、测试

测试程序:
#include  
#include  
#include  
      
      
int main(int argc,char **argv)  
{  
    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;  
}  

编译:
#arm-linux-g++ -o opencv_test opencv_test.cpp -I /opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/include/opencv -L /opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/lib -lopencv_core -lopencv_highgui -lpthread -lrt

opencv库编译参考了http://blog.csdn.net/sun_x_t/article/details/7261944 。

阅读(978) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~