码迷,mamicode.com
首页 > 其他好文 > 详细

Opencv交叉编译到ARM(基于Qt)

时间:2015-08-08 16:42:01      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:qt   opencv   交叉编译   

*:前提是Qt交叉编译已经完成,并能正常使用。

1.下载Opencv2.2.0并解压,在解压后的目录下新建一个release目录。

2.安装cmakecmake-gui

3.执行命令:cmake-gui

         错误提示和解决:

Issue 2. ImportError: No module named sphinx:

Just copy the following line, then this problem disappear.

yum install python-sphinx

Issue 3. ImportError: No module named numpy.distutils

yum install numpy.i686

4.设置源码路径和编译后文件的保存路径。

5.configure,设置交叉编译工具:

*!:注意:1只能写Linux ,不能写linux或者arm-linux 。不然就算编译通过了,在ARM板子上运行会提示:./opencv0:error while loading shared libraries: ../../lib/libopencv_core.so: cannot openshared object file: No such file or directory

         2填写交叉编译arm-linux-的安装路径

         3.一定要选择:Search in Target Root 。否者,编译到59%左右肯定会报错:

/usr/include/bits/mathinline.h:675:3: error: unknown register name ‘st‘ in ‘asm‘  

/usr/include/bits/mathinline.h:675:3: error: unknown register name ‘st‘ in ‘asm‘  

/usr/include/bits/mathinline.h:675:3: error: unknown register name ‘st‘ in ‘asm‘ 

技术分享

6.CMAKE_BUILD_TYPERelease ;

         取消WITH-TH-GTK

         取消WITH-TIFF

         选择WITH-QT

         选择WITH-QTOPENGL

7.再次点configure

8.没有提示错误的话,点Generate ,生产Makefile

9.进到编译后文件的保存路径,修改CMakeCache.txt

CMAKE_EXE_LINKER_FLAGS:STRING=‘-lpthread-lrt‘

10.执行make

11.错误和解决:

(1),79%报错:

../home/xin/tiaozhansai/OpenCV-2.2.0/modules/ml/src/gbt.cpp:474:error: ‘expl‘ was not declared in this scope

    修改gbt.cpp14行,16行:注释掉

                    //#if ANDROID

                    #define expl(x) exp(x)

                    //#endif

       错误消除。

(2)83%

libQtGui.so.4, needed by../../lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link) 出现这个错误

是因为交叉编译器没有找到 qt 库拷贝过去(注意要把所有*.so.4文件拷贝过去)

 cp/opt/EmbedSky/qt-4.7-arm/lib/*.so.4/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/lib/

 

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.错误消除,

成功!

#make install

在安装文件夹下生成binlibinclude三个目录(我的是/usr/local/lib ,

/usr/local/include/opencv ,/usr/local/include/opencv /usr/local/include/bin

lib拷到ARM板对应的目录下(大概有12M左右)

然后创建:/etc/ld.so.conf

加入:includeld.so.conf.d/*.conf

保存,然后执行: echo"/usr/local/lib" >> /etc/ld.so.conf

再执行:ldconfig

 

 

12.测试:新建一个空的Qt工程opencv0

添加一个c++源文件。

修改工程文件:

SOURCES += \

   opencv0.cpp

LIBS+= /usr/local/lib/libopencv_calib3d.so\

   /usr/local/lib/libopencv_contrib.so \

   /usr/local/lib/libopencv_core.so \

   /usr/local/lib/libopencv_features2d.so \

   /usr/local/lib/libopencv_flann.so \

   /usr/local/lib/libopencv_gpu.so \

   /usr/local/lib/libopencv_highgui.so \

   /usr/local/lib/libopencv_imgproc.so \

   /usr/local/lib/libopencv_legacy.so \

   /usr/local/lib/libopencv_ml.so \

   /usr/local/lib/libopencv_objdetect.so \

   /usr/local/lib/libopencv_video.so

 

INCLUDEPATH+=include/opencv\

include/opencv2\

include

源文件为:

#include"cv.h"

#include"cxcore.h"

#include"highgui.h"

int main(int argc,char*argv[])

{

   IplImage *pImg;//声明IplImage指针

   pImg=cvLoadImage("/home/SMARTHOME/bin/1.png",1);//载入图片

   cvNamedWindow("Image",1);//创建窗口

   cvShowImage("Image",pImg);//显示图像

   cvWaitKey(0);//等待按键

   cvDestroyWindow("Image");//销毁窗口

   cvReleaseImage(&pImg);//释放图像

   return 0;

}

这里测试的是opencv1的接口。也可以自己写opencv2的,基于Mat类的图像显示。

13.Ot编译后的elf文件拷到开发板。并执行。

报错:OpenCV Error:Unspecified error (The function is not implemented. Rebuild the library withWindows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, installlibgtk2.0-dev and pkg-config, then re-run cmake or configure script) incvNamedWindow, file /home/zhw123/software/OpenCV-2.2.0/modules/highgui/src/window.cpp,line 274

terminate called after throwing an instanceof ‘cv::Exception‘

 what(): /home/zhw123/software/OpenCV-2.2.0/modules/highgui/src/window.cpp:274:error: (-2) The function is not implemented. Rebuild the library with Windows,GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, installlibgtk2.0-dev and pkg-config, then re-run cmake or configure script in functioncvNamedWindow

Aborted

14.因为ARM板子上没有GTK的库,所以不能用highgui的窗口创建等函数。程序改写为使用Qt窗口部件类。

创建一个简单的Qt应用程序,继承自Qwidget。然后改写构造函数:

#include "widget.h"

#include "ui_widget.h"

#include <QPixmap>

#include "widget.h"

#include <opencv2/core/core.hpp>

#include<opencv2/highgui/highgui.hpp>

#include<opencv2/imgproc/imgproc.hpp>

using namespace cv;

 

Widget::Widget(QWidget *parent) :

   QWidget(parent),

   ui(new Ui::Widget)

{

   ui->setupUi(this);

   Mat srcImage1= imread("/home/SMARTHOME/bin/1.png");//加载图片

   Mat rgbImage;

   cvtColor(srcImage1,rgbImage,CV_BGR2RGB);//转换颜色空间

   QImage img=QImage((const unsigned char *)(rgbImage.data),rgbImage.cols,

                     rgbImage.rows,rgbImage.cols*rgbImage.channels(),QImage::Format_RGB888);//创建QImage对象

   ui->label->setPixmap(QPixmap(QPixmap::fromImage(img)));

   ui->label->resize(ui->label->pixmap()->size());

   ui->label->move(0,0);

}

 

Widget::~Widget()

{

   delete ui;

}

编译,然后下载到板子,把图片放到elf文件同级目录,执行命令:./opencv0 -qws

技术分享

 

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

Opencv交叉编译到ARM(基于Qt)

标签:qt   opencv   交叉编译   

原文地址:http://blog.csdn.net/u013752202/article/details/47358389

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!