I use Qt Creator to compile an Android application. I needed to integrate OpenCV into it, and it took me half a day to configure it properly, so I want to document the steps I took here, in case somebody else ever has to do it.
相关问题
- Sorting 3 numbers without branching [closed]
- How can I create this custom Bottom Navigation on
- QML: Cannot read property 'xxx' of undefin
- How to get the background from multiple images by
- Bottom Navigation View gets Shrink Down
First, I downloaded OpenCV-2.4.10-android-sdk, and put into my project directory. It contains static libraries, and link order matters for static libraries for GCC. So you need to order them just so. This is how my .pro file looked in the end ($$_PRO_FILE_PWD_ refers to the project directory):
After that the project will compile but it will fail to run with the error
To overcome this, you need to add libopencv_java.so to your APK, and then manually load it from QtActivity.java. That's what the
ANDROID_PACKAGE_SOURCE_DIR=$$_PRO_FILE_PWD_/android
line at the end was for. Now you need to place libopencv_java.so here:You can get QtActivity.java from the Android target build directory, in my case the full path was
c:\Workspace\build-MyProject-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_0-Debug\android-build\src\org\qtproject\qt5\android\bindings\QtActivity.java
, and just copy it.Then you find those lines in it:
And load
libopencv_java.so
before them, so they become:Note that you pass
opencv_java
toSystem.loadLibrary()
, even though the file islibopencv_java.so
.Edit: I forgot to mention, but I already had installed OpenCV Manager on my phone when trying to run one of the samples that come with OpenCV-2.4.10-android-sdk, so I don't know if it's needed or not. In any event, keep it in mind, if it fail even after my steps, you might need to download OpenCV Manager (it's available on the Google Store).
Edit 2: I'm using adt-bundle-windows-x86-20140702, android-ndk-r10d, OpenCV-2.4.10-android-sdk, Qt Creator 3.3.0, and my build target is "Android for armeabi-v7a (GCC 4.9, Qt 5.4.0)".
Edit 3: From Daniel Saner's comment:
Edit 4: @myk's comment: