opencv移植在4412和imx6(yocto 3.14.28 arm-poky-linux-gnueabi )上

 宿主机:ubuntu14.04

u opencv版本:opencv2.4.13

u 交叉编译器:arm-2009q3.tar.bz2

Ubuntu下载网址:http://www.ubuntu.org.cn/index_kylin

opencv下载网址:http://opencv.org/

交叉编译器下载网址:http://www.veryarm.com/arm-none-linux-gnueabi-gcc

选择对应的版本号即可,这里用该目录下的已经下载好的文件,拷贝arm-2009q3.tar.bz2和opencv-2.4.13.zip到ubuntu,这里是/home/now。

1.       安装库文件

uptech@uptech:/home/now#sudo apt-get install build-essential 

uptech@uptech:/home/now#sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

uptech@uptech:/home/now#sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev 

uptech@uptech:/home/now# sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next

uptech@uptech:/home/now# sudo apt-get update   

uptech@uptech:/home/now# sudo apt-get install ffmpeg  

只是安装opencv的话用命令不难,为了为后面用cmake-gui进行交叉编译铺路因此这里用cmake-gui来编译先检查cmake是否安装

uptech@uptech:/home/now# cmake -version

一般是已经安装好了very good,检查cmake-gui

[html] view plain copy

uptech@uptech:/home/now# cmake-gui -version

没安装,提示准备好了,安装即可

The program 'cmake-gui' is currently not installed. You can install it by typing:  

uptech@uptech:/home/now# sudo apt-get install cmake-qt-gui 

2.       解压opencv

新建一个文件夹叫opencv,里面专门放opencv编译生成的各种东西,将下载后的文件解压到这里。

uptech@uptech:/home/now# mkdir opencv

uptech@uptech:/home/now$ cd opencv/

uptech@uptech:/home/now/opencv$ unzip /home/now/opencv-2.4.13.zip

3.       安装交叉编译器

进入/usr/local目录创建arm并解压,因权限问题,使用超级用户。

uptech@uptech:/home/now/opencv$ cd /usr/local/

uptech@uptech:/usr/local$ sudo su

[sudo] password for uptech:

root@uptech:/usr/local#

root@uptech:/usr/local$ mkdir arm

root@uptech:/usr/local/arm# tar -xjvf /home/now/arm-2009q3.tar.bz2 -C./

4.       安装交叉编译器

进入实验目录,创建移植目录arm,配置opencv。

root@uptech:/usr/local/arm# cd /home/now/opencv

root@uptech:/home/now/opencv# ls

opencv-2.4.13

root@uptech:/home/now/opencv# mkdir arm

root@uptech:/home/now/opencv# cmake-gui

选择源代码路径和移植路径如图:

点击Configure,选择最后一项。

Operating System:arm-linux(填写名称任意)。

C:交叉编译器arm-none-linux-gnueabi-gcc路径。

C++:交叉编译器arm-none-linux-gnueabi-g++路径。

点击Finish。

修改安装路径,这里是/usr/local/opencv-arm。

增加:JPEG和PNG选项

去掉:1394

点击Configure,然后在点击Generate,然后关闭。进入arm目录make编译。

root@uptech:/home/now/opencv# cd arm/

root@uptech:/home/now/opencv/arm# ls

3rdparty               CPackSourceConfig.cmake  modules

apps                   CTestTestfile.cmake      opencv2

bin                    cvconfig.h               OpenCVConfig.cmake

CMakeCache.txt         data                    OpenCVConfig-version.cmake

CMakeFiles             doc                      OpenCVModules.cmake

cmake_install.cmake    include                  unix-install

cmake_uninstall.cmake  junk                     version_string.tmp

CopyOfCMakeCache.txt   lib

CPackConfig.cmake      Makefile

root@uptech:/home/now/opencv/arm# make

出现问题:

../../lib/libopencv_core.so: undefinedreference to `pthread_spin_init'

../../lib/libopencv_core.so: undefinedreference to `pthread_spin_unlock'

../../lib/libopencv_core.so: undefinedreference to `pthread_spin_lock'

../../lib/libopencv_core.so: undefinedreference to `pthread_spin_destroy'

../../lib/libopencv_core.so: undefinedreference to `pthread_once'

../../lib/libopencv_core.so: undefined referenceto `clock_gettime'

../../lib/libopencv_core.so: undefinedreference to `pthread_spin_trylock'

修改目录下的CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原来为空,加上-lpthread –lrt –ldl,继续make编译。

然后安装,会在/usr/local/opencv-arm目录。

root@uptech:/home/now/opencv/arm# make install

……

root@uptech:/home/now/opencv/arm# ls /usr/local/opencv-arm

bin include  lib  share

5.       编写测试程序

创建测试目录,编写test.c,测试程序是将彩色图片1.bmp变成灰白1_1.bmp。

root@uptech:/home/now/opencv/arm# cd ..

root@uptech:/home/now/opencv/# mkdir opencv_test/

root@uptech:/home/now/opencv/# cd opencv_test/

root@uptech:/home/now/opencv/opencv_test# vim test.c

#include "cv.h" 

#include "cxcore.h" 

#include "highgui.h"

 

int main(int argc,char **argv) 

   CvCapture* capture = NULL; 

   IplImage* pImg = NULL;

   IplImage* pImg1 = NULL;

   fprintf(stderr, "123");  

   pImg = cvLoadImage("1.bmp",1);

   fprintf(stderr, "456"); 

   pImg1 =cvCreateImage(cvSize(pImg->width,pImg->height),IPL_DEPTH_8U,1);

   fprintf(stderr, "456"); 

   cvCvtColor(pImg,pImg1,CV_RGB2GRAY);

   fprintf(stderr, "789");  

 

   cvSaveImage("1_1.bmp",pImg1);

 

   fprintf(stderr, "109"); 

   cvReleaseImage( &pImg );  

   cvReleaseImage( &pImg1 );  

   return 0; 

}

拷贝三个头文件cv.h,cxcore.h,highgui.h到当前目录。因为使用的是opencv的头文件,这些头文件在/usr/local/opencv-arm/include/下

root@uptech:/home/now/opencv/opencv_test# cp/usr/local/opencv-arm/include/opencv/cv.h ./

root@uptech:/home/now/opencv/opencv_test# cp/usr/local/opencv-arm/include/opencv/cxcore.h ./

root@uptech:/home/now/opencv/opencv_test# cp/usr/local/opencv-arm/include/opencv/highgui.h ./

用交叉编译器编译,-I和-L为头文件路径和库文件路径,-l为opencv库参数。生成测试文件test。

root@uptech:/home/now/opencv/opencv_test# /usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-g++test.c -o test -I/usr/local/opencv-arm/include/ -L/usr/local/opencv-arm/lib/-lopencv_core -lopencv_highgui -lopencv_imgproc

test.c:24: note: the mangling of 'va_list'has changed in GCC 4.4

root@uptech:/home/now/opencv/opencv_test# ls

cv.h cxcore.h  highgui.h  test test.c

将测试程序和opencv-arm拷贝到共享目录imx6下,方便arm开发板去访问。将一张1.bmp的图片放到imx6目录下。

root@uptech:/home/now/opencv/opencv_test# cp test /imx6

root@uptech:/home/now/opencv/opencv_test# cp /usr/local/opencv-arm /imx6/ -rf

root@uptech:/home/now/opencv/opencv_test# cp /home/now/1.bmp /imx6

6.       arm上测试

打开开发板,配置IP地址。

[root@yaffs]# ifconfig eth0 192.168.88.184

挂载到将宿主机共享目录imx6挂载到开发板。

[root@yaffs]# mountnfs 192.168.88.184:/imx6 /mnt/nfs/

[root@yaffs]# cd /mnt/nfs/

设置当前环境变量,执行应用程序,会生成1_1.bmp。

[root@ nfs]# export LD_LIBRARY_PATH=$PWD/opencv-arm/lib

[root@ nfs]# ./test

123456456789109[root@nfs]# ls

1.bmp             1_1.bmp    test

[root@UP-TECH nfs]#

因为开发板不支持gtk图形显示,所以不能在开发板上显示,只能将图片拷贝出来在PC上去查看。

测试效果图,左边是彩色图像,右边是经过opencv处理过的灰白图像:













imx6航移植

你可能感兴趣的:(移植)