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

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

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

2.安裝cmake和cmake-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%左右肯定会报错:

archival/rpm.c:351:10: error: invalid ‘asm’: invalid operand for code ‘w’

xxx.c:error: invalid ‘asm’: invalid operand for code ‘w’

6.CMAKE_BUILD_TYPE填Release ;

     取消WITH-TH-GTK

     取消WITH-TIFF

     選擇WITH-QT

     選擇WITH-QTOPENGL

7.再次點configure

8.沒有提示錯誤的話,點Generate,生產Makefile。

9.進到编译后文件的保存路徑,修改CMakeCache.txt:

CMAKE_EXE_LINKER_FLAGS:STRING=’-lpthread -lrt’ 【注意:-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.cpp中14行,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)⚠️ the use of tmpnam' is dangerous, better usemkstemp’

…/…/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

在安裝文件夾下生成bin、lib、include三個目錄(我的是/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

#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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值