0

I would like to create a QT widget (C++) and use the OpenCV library (C++) and deploy it to Android.

I have installed QT for Android and the necessary files mentioned in http://qt-project.org/doc/qt-5/androidgs.html such as the NDK,SDK etc. The mingw compiler is included in QT for Android so I didnt have to install this again.

I have no problem deploying a QT widget to android. The problem is using the OpenCV library in the QT widget and then deploying it.

I have tried two options to use OpenCV in my QT project:

  1. As QT for Android comes with the mingw compiler I have compiled the OpenCV library from source using CMake and the mingw compiler. Then i have included the header files and linked the libraries in the project file of QT . This option does not work . I am used to this method of including and would also like to use other libraries such as Boost and Eigen in the same way.

  2. I have downloaded the OPENCV android SDK and included it's header files and linked it's libraries in the project file of QT. This still hasnt worked.

Basically all I want to do is solely code in C++, hence using a widget and not qtquick(qml). Please can you let me know which ,if any, of the above steps is correct and what changes I have to make.

On another note does anyone know how I can speed up the emulator , I have an AMD processor so cant take advantage of intels tools. And where I can get the AVD settings for Samsung Note 4?

Thanks very much!!

Project file for option 1:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = test3
TEMPLATE = app


LIBS+= C:\programs\opencv\RELEASE\lib\\\*
INCLUDEPATH+= C:\programs\opencv\RELEASE\install\include\

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

CONFIG += mobility
MOBILITY = 

Errors for option 1:

12:18:17: Starting: "C:\programs\QT\Tools\mingw482_32\bin\mingw32-make.exe" 
C:\programs\QT\5.3\android_armv7\bin\qmake.exe -spec android-g++ CONFIG+=debug -o Makefile ..\test3\test3.pro
The system cannot find the path specified.
C:\programs\android-ndk-r10c/toolchains/arm-linux-androideabi-4.9/prebuilt/windows/bin/arm-linux-androideabi-g++ --sysroot=C:\programs\android-ndk-r10c/platforms/android-9/arch-arm/ -Wl,-soname,libtest3.so -Wl,--no-undefined -Wl,-z,noexecstack -shared -o libtest3.so main.obj mainwindow.obj moc_mainwindow.obj   -LC:\programs\android-ndk-r10c/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a -LC:\programs\android-ndk-r10c/platforms/android-9/arch-arm//usr/lib C:\programs\opencv\RELEASE\lib\\* -LC:/programs/QT/5.3/android_armv7/lib -lQt5Widgets -Lc:\Utils\android\ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a -Lc:\Utils\android\ndk/platforms/android-9/arch-arm//usr/lib -LC:\Utils\icu32_51_1_mingw482\lib -LC:\utils\postgresql\pgsql\lib -LC:\utils\mysql\mysql\lib -LC:\Utils\pgsql\lib -LC:\temp\opensll-android-master\openssl-android-master\lib -LC:\programs\QT\5.3\android_armv7/lib -lQt5Gui -lQt5Core -lGLESv2 -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc
..\..\opencv\RELEASE\install\include/opencv2/core/mat.hpp:278: error: undefined reference to 'cv::fastFree(void*)'
..\..\opencv\RELEASE\install\include/opencv2/core/mat.hpp:298: error: undefined reference to 'cv::Mat::copySize(cv::Mat const&)'
..\..\opencv\RELEASE\install\include/opencv2/core/mat.hpp:367: error: undefined reference to 'cv::Mat::deallocate()'
..\test3/main.cpp:23: error: undefined reference to 'cv::imread(std::string const&, int)'
..\test3/main.cpp:31: error: undefined reference to 'cv::namedWindow(std::string const&, int)'
..\test3/main.cpp:32: error: undefined reference to 'cv::_InputArray::_InputArray(cv::Mat const&)'
Makefile:82: recipe for target 'libtest3.so' failed
..\test3/main.cpp:32: error: undefined reference to 'cv::imshow(std::string const&, cv::_InputArray const&)'
..\test3/main.cpp:34: error: undefined reference to 'cv::waitKey(int)'
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [libtest3.so] Error 1
12:18:22: The process "C:\programs\QT\Tools\mingw482_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project test3 (kit: Android for armeabi-v7a (GCC 4.9, Qt 5.3.2))
When executing step "Make"
12:18:22: Elapsed time: 00:04.

Project file for option 2:

   #-------------------------------------------------
#
# Project created by QtCreator 2014-12-05T18:06:24
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = test3
TEMPLATE = app

INCLUDEPATH+= C:\programs\opencvandroidsdk\sdk\native\jni\include

LIBS += -LC:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\
-lopencv_contrib \
-lopencv_legacy \
-lopencv_ml \
-lopencv_objdetect \
-lopencv_calib3d \
-lopencv_video \
-lopencv_features2d \
-lopencv_highgui \
-lopencv_androidcamera \
-lopencv_flann \
-lopencv_imgproc \
-lopencv_core

LIBS += -LC:\programs\opencvandroidsdk\sdk\native\3rdparty\libs\armeabi-v7a\
-llibjpeg \
-llibpng \
-llibtiff \
-llibjasper \
-ltbb \
-lIlmImf

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

CONFIG += mobility
MOBILITY =

Errors for option 2:

18:24:53: Running steps for project test3...
18:24:53: Configuration unchanged, skipping qmake step.
18:24:53: Starting: "C:\programs\QT\Tools\mingw482_32\bin\mingw32-make.exe" 
mingw32-make: Nothing to be done for 'first'.
18:24:55: The process "C:\programs\QT\Tools\mingw482_32\bin\mingw32-make.exe" exited normally.
18:24:55: Starting: "C:\programs\QT\Tools\mingw482_32\bin\mingw32-make.exe" INSTALL_ROOT="C:\programs\QT projects\build-test3-Android_for_armeabi_v7a_GCC_4_9_Qt_5_3_2-Release\android-build" install
copy /y "libtest3.so" "C:\programs\QT projects\build-test3-Android_for_armeabi_v7a_GCC_4_9_Qt_5_3_2-Release\android-build\libs\armeabi-v7a\libtest3.so"
The system cannot find the path specified.
        0 file(s) copied.
Makefile:1627: recipe for target 'install_target' failed
mingw32-make: [install_target] Error 1 (ignored)
18:24:57: The process "C:\programs\QT\Tools\mingw482_32\bin\mingw32-make.exe" exited normally.
Error while building/deploying project test3 (kit: Android for armeabi-v7a (GCC 4.9, Qt 5.3.2))
When executing step "Deploy to Android device"
18:27:00: Elapsed time: 02:07.
Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47
West1234
  • 189
  • 14

1 Answers1

1

For option 2:

Change

LIBS += \
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_contrib.a \
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_legacy.a \
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_ml.a \
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_objdetect.a\
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_calib3d.a \
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_video.a \
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_features2d.a \
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_highgui.a \
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_androidcamera.a \
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_flann.a \
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_imgproc.a \
C:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_core.a \
C:\programs\opencvandroidsdk\sdk\native\3rdparty\libs\armeabi-v7a\liblibjpeg.a \
C:\programs\opencvandroidsdk\sdk\native\3rdparty\libs\armeabi-v7a\liblibpng.a \
C:\programs\opencvandroidsdk\sdk\native\3rdparty\libs\armeabi-v7a\liblibtiff.a \
C:\programs\opencvandroidsdk\sdk\native\3rdparty\libs\armeabi-v7a\liblibjasper.a \
C:\programs\opencvandroidsdk\sdk\native\3rdparty\libs\armeabi-v7a\libtbb.a \

to:

LIBS += -LC:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a \  
-lopencv_legacy \  
-lopencv_ml \  
-lopencv_objdetect\  
... \  
-ltbb
Marian Munteanu
  • 349
  • 1
  • 10
  • Thanks I am now getting an error "extra characters after expression" I have updated my question to show the error – West1234 Dec 07 '14 at 15:34
  • I'm sorry, it's my fault. Remove libopencv_contrib.a from -LC:\programs\opencvandroidsdk\sdk\native\libs\armeabi-v7a\libopencv_contrib.a . So -L is for lib directory, and -l for library files. To add libBlaBla.a use -lBlaBla (without lib and .a) – Marian Munteanu Dec 07 '14 at 16:01
  • now I just have deployment errors (see above) any tips? – West1234 Dec 07 '14 at 16:34
  • My advice is to use a path without spaces when dealing with Qt(folder "QT projects"). Now, the above error is from windows command "copy", "The system cannot find the path specified.", but there's no need to go into that until you try to build in a folder without spaces. – Marian Munteanu Dec 07 '14 at 16:53
  • thanks will do , from your experience is it possible now that i have included opencv and all the neccesary android requirements to code a widget in c++ using OPENCV c++ example code and port to android. basically my question is can i take a normal opencv example i see online and put it in widget and port it to android now. thanks – West1234 Dec 07 '14 at 17:02
  • First, try to build and test on Windows. I never used OpenCV on Android, so I can't say. – Marian Munteanu Dec 07 '14 at 17:31
  • thanks Marian, for other libraries such as boost and eigen can i just compile them from source using mingw and then include/link, or do i need to get a boost android sdk like i needed the opencv sdk – West1234 Dec 07 '14 at 18:33
  • A simple step-by-step tutorial on how to build boost for Android: http://munteanumarian.blogspot.com/2014/10/build-boost-for-android.html – Marian Munteanu Dec 07 '14 at 18:41