Unsolved OpenCV-4.5.2 and Android NDK20, Kit armeabi-v7a, C++
-
Hi everyone !
I'm new bie, and I don't speak English well , I need use opencv lib for Qt, but have error code :
clang++: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [libuntitled_armeabi-v7a.so] Error 1 22:00:06: The process "C:\Qt\android-ndk-r20b\prebuilt\windows-x86_64\bin\make.exe" exited with code 2. Error while building/deploying project untitled (kit: Android for armeabi-v7a,arm64-v8a,x86,x86_64 (Clang Qt 5.14.2 for Android)) When executing step "Make"
With .pro file:
OPENCVSDKNATIVE = C:/OpenCV-android-sdk/sdk/native INCLUDEPATH += $$OPENCVSDKNATIVE/jni/include equals(ANDROID_TARGET_ARCH, armeabi-v7a) { message("setting armeabi-v7a OPENCV libs") # OPENCV LIBS LIBS +=\ -L"$$OPENCVSDKNATIVE/3rdparty/libs/armeabi-v7a"\ -L"$$OPENCVSDKNATIVE/staticlibs/armeabi-v7a"\ -llibtiff -llibpng -lIlmImf -llibprotobuf\ -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio\ ANDROID_EXTRA_LIBS += $$OPENCVSDKNATIVE/libs/armeabi-v7a/libopencv_java4.so }
Can you help me?
Many thanks ! -
@DQUY05 said in OpenCV-4.5.2 and Android NDK20, Kit armeabi-v7a, C++:
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Please post the actual linker error (should be above that line).
-
I fixed the error, but the function is always false , and the camera cannot be opened
capture.open(1); if(!capture.isOpened()) { ui->inform->setText("NG camera"); qDebug() << "Could not open camera" << 1; } else { ui->inform->setText("OK camera"); qDebug() << "Opened camera" << 1; }
.cpp file
#include <opencv2/core.hpp> #include "opencv2/opencv.hpp" #include <opencv2/core/mat.hpp> #include <opencv2/core/mat.inl.hpp> #include <opencv2/core.hpp> #include <opencv2/videoio.hpp> #include <opencv2/highgui.hpp> #include <opencv2/imgproc.hpp> // cv::Canny() #include <iostream>
.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 \ -llibpng \ -lIlmImf \ -ltbb \ -ltegra_hal \ -lade \ -lcpufeatures \ -lopencv_java4 \ ANDROID_EXTRA_LIBS = $$OPENCV_ANDROID/sdk/native/libs/arm64-v8a/libopencv_java4.so } else { error("Unsupported architecture: $$ANDROID_TARGET_ARCH") } }
App output
D libuntitled_arm64-v8a.so: Could not open camera 1
I hope you will help me,
Thanks! -
@DQUY05 said in OpenCV-4.5.2 and Android NDK20, Kit armeabi-v7a, C++:
I hope you will help me
This is an issue with OpenCV, not Qt. You should ask in a OpenCV forum.
One possible reason for your problem: on Android an app has to request rights to access camera. -
@jsulm said in OpenCV-4.5.2 and Android NDK20, Kit armeabi-v7a, C++:
@DQUY05 said in OpenCV-4.5.2 and Android NDK20, Kit armeabi-v7a, C++:
I hope you will help me
This is an issue with OpenCV, not Qt. You should ask in a OpenCV forum.
One possible reason for your problem: on Android an app has to request rights to access camera.I have add a function that requires to use the camera already
#include <QtAndroidExtras/QtAndroid> #include <QtAndroidExtras/QtAndroid> #include <QtMultimedia/qmultimedia.h>
and
auto result = QtAndroid::checkPermission(QString("android.permission.CAMERA")); if(result == QtAndroid::PermissionResult::Denied){ QtAndroid::PermissionResultMap resultHash = QtAndroid::requestPermissionsSync(QStringList({"android.permission.CAMERA"})); if(resultHash["android.permission.CAMERA"] == QtAndroid::PermissionResult::Denied) { } }
and .xml file
<uses-permission android:name="android.permission.CAMERA"/> <uses-feature android:name="android.hardware.camera" android:required="true"/> <uses-feature android:name="android.hardware.camera.autofocus" android:required="true"/> <uses-feature android:name="android.hardware.camera.front" android:required="true"/> <uses-feature android:name="android.hardware.camera.front.autofocus" android:required="true"/>
But not work!
Many thanks!