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
For OpenCV 4, sashoalm's approach did not work for me until I adapted it:
OPENCV_ANDROID
which points to that directory later.Add the following snippet to your *.pro
-file:
android {
contains(ANDROID_TARGET_ARCH,arm64-v8a) {
isEmpty(OPENCV_ANDROID) {
error("Let OPENCV_ANDROID point to the opencv-android-sdk, recommended: v4.0")
}
INCLUDEPATH += "$$OPENCV_ANDROID/sdk/native/jni/include"
LIBS += \
-L"$$OPENCV_ANDROID/sdk/native/libs/arm64-v8a" \
-L"$$OPENCV_ANDROID/sdk/native/3rdparty/libs/arm64-v8a" \
-llibtiff \
-llibjpeg-turbo \
-llibjasper \
-llibpng \
-lIlmImf \
-ltbb \
-lopencv_java4 \
ANDROID_EXTRA_LIBS = $$OPENCV_ANDROID/sdk/native/libs/arm64-v8a/libopencv_java4.so
} else {
error("Unsupported architecture: $$ANDROID_TARGET_ARCH")
}
}
This will work for the arm64-v8a
only. If you happen to build for another architecture (apparently 32-Bit is still the default for Qt@Android), you must change the .../libs/arm64-v8a
part of the paths (occurs 3 times) and the same to match your actual target-architecture (the contains(...)
-part in the second line of the snippet).
qmake
where to find the SDK. Add the following to qmake-call: "OPENCV_ANDROID=/path/to/OpenCV-android-sdk"
.
qmake example.pro "OPENCV_ANDROID=/home/user/OpenCV-android-sdk"
from command line."OPENCV_ANDROID=..."
to the "Additional arguments"-field. You can find it after enabling the Project-Mode in the Build-section of the android-kit. Expand the qmake-field under Build Steps