OPENCV programming at the same time on win and Android

Source: Internet
Author: User
Tags deprecated scalar

when designing a project for Android image processing based on QT, you can start debugging on Windows First, and then convert the code to adnroid when it is mature. This is the case only for widgets, if the use of Qtquick is the same. The following steps are specific: 1, when the project was created, choose Android and Desktop two categories (provided that the installation time has been selected)so, in the process of programming, we can choose by switchingIf you have a project that is already configured with Kti (build suite), you can remove the. pro.user file from the directory and then reopen the project, and then automatically jump out of the build Suite Configuration Interface
2. configuration file:modification of the configuration file is the main point of knowledge, first of all under different platforms, to fill in different prefixes. For PC platforms is win32 {……}for Android platform is android {……}The case is not writable, and it is also the configuration of the OPENCV base environment. What you need to do for the PC platform is to configure the system path, set the Include and Lib paths, and what you need to do for the Android platformset the Include and Lib paths, andlibopencv_java3.socopy to the last. apk. Refer to the configuration file below, where the important part is already bold. QT + = Quick
QT + = Multimedia
CONFIG + = c++11

Win32 {
Message ("Currently using PC Configuration")
WIN32_OPENCV = D:/jsxyheluopencv/new-qt-dll/install
Includepath + = \
$ $WIN 32_OPENCV/INCLUDE/OPENCV \
$ $WIN 32_opencv/include/opencv2 \
$ $WIN 32_opencv/include
LIBS + = \
$ $WIN 32_opencv/x86/mingw/lib/
LIBOPENCV_CORE320.DLL.A\$ $WIN 32_opencv/x86/mingw/lib/libopencv_highgui320.dll.a\
$ $WIN 32_opencv/x86/mingw/lib/libopencv_imgproc320.dll.a\
$ $WIN 32_opencv/x86/mingw/lib/libopencv_imgcodecs320.dll.a\
$ $WIN 32_opencv/x86/mingw/lib/libopencv_highgui320.dll.a\
$ $WIN 32_OPENCV/X86/MINGW/LIB/LIBOPENCV_VIDEOIO320.DLL.A
}

Android {
Message ("Currently using Android Configuration")
ANDROID_OPENCV = d:/opencv-android-sdk/sdk/native
Includepath + = \
$ $ANDROID _OPENCV/JNI/INCLUDE/OPENCV \
$ $ANDROID _opencv/jni/include/opencv2 \
$ $ANDROID _opencv/jni/include \
LIBS + = \
$ $ANDROID _OPENCV/LIBS/ARMEABI-V7A/LIBOPENCV_ML.A \
$ $ANDROID _opencv/libs/armeabi-v7a/libopencv_objdetect.a \
$ $ANDROID _opencv/libs/armeabi-v7a/libopencv_calib3d.a \
$ $ANDROID _opencv/libs/armeabi-v7a/libopencv_video.a \
$ $ANDROID _opencv/libs/armeabi-v7a/libopencv_features2d.a \
$ $ANDROID _OPENCV/LIBS/ARMEABI-V7A/LIBOPENCV_HIGHGUI.A \
$ $ANDROID _opencv/libs/armeabi-v7a/libopencv_flann.a \
$ $ANDROID _opencv/libs/armeabi-v7a/libopencv_imgproc.a \
$ $ANDROID _opencv/libs/armeabi-v7a/libopencv_core.a \
$ $ANDROID _opencv/3rdparty/libs/armeabi-v7a/liblibjpeg.a \
$ $ANDROID _opencv/3rdparty/libs/armeabi-v7a/liblibpng.a \
$ $ANDROID _opencv/3rdparty/libs/armeabi-v7a/liblibtiff.a \
$ $ANDROID _opencv/3rdparty/libs/armeabi-v7a/liblibjasper.a \
$ $ANDROID _OPENCV/3RDPARTY/LIBS/ARMEABI-V7A/LIBTBB.A \
$ $ANDROID _OPENCV/3RDPARTY/LIBS/ARMEABI-V7A/LIBTEGRA_HAL.A \
$ $ANDROID _opencv/libs/armeabi-v7a/libopencv_java3.so
}

# The followingDefineMakes your compiler emit warningsifUse
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API In order to know what to port your code away from it.
Defines + = Qt_deprecated_warnings

# can also make your code fail to compileifYou use deprecated APIs.
# in order to DoSo, uncomment the following line.
# You can also the select to disable deprecated APIs is only up to a certain version of Qt.
#DEFINES + = qt_disable_deprecated_before=0x060000 # Disables all the APIs DEPRECATED before QT 6.0.0

SOURCES + = main.cpp \
Todocpp.cpp \
Calibration.cpp

RESOURCES + = QML.QRC

# Additional Import path used to resolve QML modules in Qt Creator ' s code model
Qml_import_path =

# Additional Import path used to resolve QML modules just for Qt Quick Designer
Qml_designer_import_path =

# Default rules for deployment.
Qnx:target.path =/tmp/$${target}/bin
Else:unix:!android:target.path =/opt/$${target}/bin
!isempty (Target.path): Installs + = target

HEADERS + = \
Todocpp.h \
Calibration.h

Distfiles + = \
Android/androidmanifest.xml \
Android/gradle/wrapper/gradle-wrapper.jar \
Android/gradlew \
Android/res/values/libs.xml \
Android/build.gradle \
Android/gradle/wrapper/gradle-wrapper.properties \
Android/gradlew.bat

Contains (android_target_arch,armeabi-v7a) {
Android_extra_libs = \
D:/opencv-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_java3.so
}

Android_package_source_dir = $ $PWD/android

and set the correct environment variables (how to compile OpenCV under Windows and Android) please refer to other blog posts. 3. Writing interface and codefor illustrative convenience, display a self-generated circle on a simple widget. The OPENCV code is called for both the generation of the circle and the final display. So if this is successful, it proves that the OPENCV environment is properly configured. #include"Mainwindow.h"
#include"Ui_mainwindow.h"
using namespaceCv
Mat tmp;
Mainwindow::mainwindow (Qwidget *parent):
Qmainwindow (parent),
UiNewUi::mainwindow)
{
UI->SETUPUI ( This);
}

Mainwindow::~mainwindow ()
{
DeleteUi
}

voidMainwindow::on_pushbutton_pressed ()
{
Mat src (Size (640,480), Cv_8uc1,cv::scalar (255));
Circle (Src,point (100,100), 100,scalar (0),-1);
Format conversion
Qpixmap qpixmap = mat2qimage (src);
Display a picture on a label
Ui->label->setpixmap (QPIXMAP);
}

Format conversion
Qpixmap mat2qimage (Mat src)
{
Qimage img;
Conversion based on QT display method
if(Src.channels () = = 3)
{
Cvtcolor (SRC, tmp, CV_BGR2RGB);
img = Qimage ((Const unsigned Char*) (Tmp.data), Tmp.cols, Tmp.rows, qimage::format_rgb888);
}
Else
{
img = Qimage ((Const unsigned Char*) (Src.data), Src.cols, Src.rows, Qimage::format_grayscale8);
}
Qpixmap qimg = Qpixmap::fromimage (IMG);
returnqimg;
}
4. Results and summaryconfiguration on two types of platforms, the original reason is to be able to speed up the project at the beginning, the ANDROID+OPENCV handler debugging speed, the main difficulty lies in the configuration of the. Pro file. How to improve the speed of implementation in the process of project practice? We continue to share in the following articles. Thanks for reading this, hope to help!





From for notes (Wiz)

OPENCV programming at the same time on win and Android

Related Article

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.