I want to use OpenCV 3.4.1 in my Qt for Android project, but I get build errors such as :
.../libopencv_core.a(system.cpp.o):system.cpp:function cv::HWFeatures::initialize(): error: undefined reference to 'android_getCpuFeatures'
.../libopencv_core.a(arithm.cpp.o):arithm.cpp:function cv::hal::cmp8u(unsigned char const*, unsigned int, unsigned char const*, unsigned int, unsigned char*, unsigned int, int, int, void*): error: undefined reference to 'carotene_o4t::isSupportedConfiguration()'
.../libopencv_core.a(arithm.cpp.o):arithm.cpp:function cv::hal::cmp8u(unsigned char const*, unsigned int, unsigned char const*, unsigned int, unsigned char*, unsigned int, int, int, void*): error: undefined reference to 'carotene_o4t::cmpGE(carotene_o4t::Size2D const&, unsigned char const*, int, unsigned char const*, int, unsigned char*, int)'
Full error file here (too big for Stack Overflow)
This is what I wrote in my *.pro file :
QT += core quick quickcontrols2 widgets
CONFIG += c++11 console
#...
OPENCVSDKNATIVE = $$PWD/3rdparty/opencv-3.4.1-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" -llibtiff -llibjpeg -llibjasper -llibpng -llibwebp -lIlmImf -ltbb -ltegra_hal
LIBS += -L"$$OPENCVSDKNATIVE/staticlibs/armeabi-v7a" -lopencv_core -lopencv_imgcodecs -lopencv_imgproc
ANDROID_EXTRA_LIBS += $$OPENCVSDKNATIVE/libs/armeabi-v7a/libopencv_java3.so
}
and what I put in my cpp code :
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
int main (int argc, char *argv[]){
QString imgPath = "path_to_my_image.jpg";
cv::Mat image = cv::imread(imgPath.toStdString().c_str());
//...
}
How to use/link OpenCV 3.4.1 in Qt for Android ?
Versions used :
EDIT 1 : I updated the LIBS var in the *.pro file, but still issues
LIBS +=\
-L"$$OPENCVSDKNATIVE/3rdparty/libs/armeabi-v7a"\
-L"$$OPENCVSDKNATIVE/staticlibs/armeabi-v7a"\
-llibtiff -llibjpeg -llibjasper -llibpng -lIlmImf -llibprotobuf\
-lopencv_core -lopencv_imgproc -lopencv_imgcodecs\
-ltbb -lcpufeatures -ltegra_hal
The issues occured because of bad definition of the LIBS
var in the *.pro file.
This is a valid one (I added -lcpufeatures
and put the libs in the good order)
LIBS +=\
-L"$$OPENCVSDKNATIVE/3rdparty/libs/armeabi-v7a"\
-L"$$OPENCVSDKNATIVE/staticlibs/armeabi-v7a"\
-lopencv_imgcodecs -lopencv_imgproc -lopencv_core -llibtiff -llibjpeg -llibjasper -llibpng -lIlmImf -llibprotobuf -llibwebp -ltbb -lcpufeatures -ltegra_hal