OpenCV cross-compiling to arm (QT-based)

Source: Internet
Author: User
Tags gtk

*: The prerequisite is that Qt cross-compilation is complete and can be used normally.

1. download Opencv2.2.0 and unzip and create a new release directory under the extracted directory.

2. Install cmake and Cmake-gui.

3. execution command:Cmake-gui

Error Hints and resolution:

Issue 2. Importerror:no Module named Sphinx:

Just Copy the following line and then this problem disappear.

Yum Install Python-sphinx

Issue 3. Importerror:no module named Numpy.distutils

Yum Install numpy.i686

4. set the source path and save path of the compiled file.

5. Point Configure, set the cross-compilation tool:

*! : note:1 can only write Linux, can not write Linux or arm-linux. Otherwise, if the compiler passes, running on the ARM board will prompt:./opencv0:error while loading shared libraries:.. /.. /lib/libopencv_core.so:cannot openshared object File:no such file or directory

2 fill in the installation path for cross-compilation arm-linux-

3. Be sure to select:Search in Target Root. No, compile to 59% around will definitely error:

/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_type fill Release;

Cancel with-th-gtk

Cancel with-tiff

Select with-qt

Select With-qtopengl

7. Point Configure again

8. without prompting the error, point Generate, production Makefile.

9. go to the save path of the compiled file, modify the CMakeCache.txt:

cmake_exe_linker_flags:string= '-LPTHREAD-LRT '

execute make

Error and resolution:

(1), 79% error:

.. /home/xin/tiaozhansai/opencv-2.2.0/modules/ml/src/gbt.cpp:474:error: ' expl ' is not declared in this scope

Modify gbt.cpp in line, line : Comment out

#if ANDROID

#define EXPL (x) exp (x)

#endif

Error elimination.

(2) 83%

libqtgui.so.4, needed by. /.. /lib/libopencv_highgui.so, not found (try Using-rpath or-rpath-link) This error occurs

is because the cross compiler did not find the QT Library copy in the past (note to copy all *.so.4 files past)

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

(4), 96% error:

cmakefiles/opencv_test.dir/src/highguitest.obj:in function ' cv_highguitest::run (int) ':

Highguitest.cpp: (. text._zn14cv_highguitest3runei+0x18): warning:the use of ' tmpnam ' are dangerous, better use ' mkstemp '

.. /.. /lib/libopencv_features2d.so:undefined reference to ' Cv::sift::sift (double, bool, bool, int, int, int, int) '

Workaround: Under opencv2.2.0/modules/features2d/src/sift.cpp

#ifdef __arm__

#define Arm_no_sift

#endif

comment out #define Arm_no_sift. Error elimination,

Success!

#make Install

Generate bin,Lib,include three directories under the installation folder (my is /usr/local/lib,

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

The Lib is copied to the corresponding directory of ARM Board ( about 12M ).

Then create:/etc/ld.so.conf

Join:includeld.so.conf.d/*.conf

Save, then execute: echo "/usr/local/lib" >>/etc/ld.so.conf

Re-execution:ldconfig

Test: Create an empty Qt project opencv0

Add a C + + source file.

Modify the project file:

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

The source files are:

#include "Cv.h"

#include "cxcore.h"

#include "highgui.h"

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

{

iplimage *pimg;// declaration iplimage Pointer

pimg=cvloadimage ("/home/smarthome/bin/1.png", 1);// load Picture

Cvnamedwindow ("Image", 1);// Create window

cvshowimage ("image", pImg);// display image

cvwaitkey (0);// Wait for the button

Cvdestroywindow ("Image");// Destroy window

cvreleaseimage (&pimg);// release image

return 0;

}

The opencv1 interface is tested here. You can also write your own Opencv2 , based on the Mat class image display.

Copy the Ot compiled elf file to the Development Board. and execute.

Error:OpenCV error:unspecified Error (the function is not implemented. Rebuild the library withwindows, GTK + 2.x or Carbon support. If you is on Ubuntu or Debian, Installlibgtk2.0-dev and Pkg-config, then re-run cmake or configure script) Incvnamedwindo W, 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 was not Implemented. Rebuild the library with windows,gtk+ 2.x or Carbon support. If you is on Ubuntu or Debian, Installlibgtk2.0-dev and Pkg-config, then re-run cmake or configure script in Functioncvna Medwindow

Aborted

because there is no GTK Library on the ARM board, you cannot create such functions with Highgui windows. The program is rewritten to use the Qt widget class.

Create a simple Qt application that inherits from Qwidget. Then rewrite the constructor:

#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");// load Picture

Mat Rgbimage;

Cvtcolor (SRCIMAGE1,RGBIMAGE,CV_BGR2RGB);// Convert color space

Qimage img=qimage ((const unsigned char *) (Rgbimage.data), Rgbimage.cols,

rgbimage.rows,rgbimage.cols*rgbimage.channels (), qimage::format_rgb888);// Create qimage Object

Ui->label->setpixmap (Qpixmap (Qpixmap::fromimage (IMG)));

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

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

}

Widget::~widget ()

{

Delete UI;

}

compile, then download to the board, put the picture in the elf file sibling directory, execute the command:./opencv0-qws

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

OpenCV cross-compiling to arm (QT-based)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.