gpt4 book ai didi

android - Android 中的 OpenCV 4.0.1 链接失败

转载 作者:太空宇宙 更新时间:2023-11-03 22:40:27 26 4
gpt4 key购买 nike

我正在将 OpenCV 库从 3.2.0 迁移到 4.0.1。在此过程中发现许多宏已被重新定义为更多 C++ 风格,例如 CV_BGR2RGB 现在是 COLOR_BGR2RGB。

当前在尝试链接 ../native/libs/x86_64/libopencv_java4.so 时遇到以下链接错误,如下所示

native/jni/include\opencv2/core/mat.inl.hpp:548: error: undefined reference to 'cv::error(int, std::string const&, char const*, char const*, int)'

native/jni/include\opencv2/core/mat.inl.hpp:561: error: undefined reference to 'cv::error(int, std::string const&, char const*, char const*, int)'

xxx_std.h:355: error: undefined reference to 'cv::putText(cv::_InputOutputArray const&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'

LabelUtils.cpp:1225: error: undefined reference to 'cv::putText(cv::_InputOutputArray const&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'

LabelUtils.cpp:2512: error: undefined reference to 'cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'

TrackingCodeDeSkew.cpp:553: error: undefined reference to 'cv::putText(cv::_InputOutputArray const&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'

TrackingCodeDeSkew.cpp:557: error: undefined reference to 'cv::putText(cv::_InputOutputArray const&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'

这是链接器命令行

    C:\Users\koush\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe  --target=x86_64-none-linux-android --gcc-toolchain=C:/Users/koush/AppData/Local/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/koush/AppData/Local/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem C:/Users/koush/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/x86_64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat
<<list of generated object files>> -llog OpenCV401/native/libs/x86_64/libopencv_java4.so src/main/jniLibs/x86_64/libzbarjni.so src/main/jniLibs/x86_64/libiconv.so -landroid -latomic -lm "C:/Users/koush/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/libsupc++.a" "C:/Users/koush/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64
/libgnustl_shared.so"

最佳答案

首先,如果您考虑随时切换回 OpenCV 3.x,您将需要像这样的向后兼容 header :


/*
* OpenCV 4.0.1 backward compatibility header.
* */

#ifndef ANDROID_DOXCAPTUREUI_OPENCV4_COMPAT_H
#define ANDROID_DOXCAPTUREUI_OPENCV4_COMPAT_H

#include <opencv2/opencv.hpp>
#include <cmath>

#if CV_MAJOR_VERSION > 3

// namespace cv;
//{
#ifndef CV_TERMCRIT_ITER
#define CV_TERMCRIT_ITER cv::TermCriteria::MAX_ITER
#endif

#ifndef CV_BGR2GRAY
#define CV_BGR2GRAY cv::COLOR_BGR2GRAY
#endif

#ifndef CV_BGR2RGB
#define CV_BGR2RGB cv::COLOR_BGR2RGB
#endif

#ifndef CV_RGB2GRAY
#define CV_RGB2GRAY cv::COLOR_RGB2GRAY
#endif

#ifndef CV_BGRA2GRAY
#define CV_BGRA2GRAY cv::COLOR_BGRA2GRAY
#endif

#ifndef CV_GRAY2RGBA
#define CV_GRAY2RGBA cv::COLOR_GRAY2RGBA
#endif

#ifndef CV_GRAY2RGB
#define CV_GRAY2RGB cv::COLOR_GRAY2RGB
#endif

#ifndef CV_GRAY2BGRA
#define CV_GRAY2BGRA cv::COLOR_GRAY2BGRA
#endif

#ifndef CV_GRAY2BGR565
#define CV_GRAY2BGR565 cv::COLOR_GRAY2BGR565
#endif

#ifndef CV_RGBA2BGR565
#define CV_RGBA2BGR565 cv::COLOR_RGBA2BGR565
#endif

#ifndef CV_RGBA2RGB
#define CV_RGBA2RGB cv::COLOR_RGBA2RGB
#endif

#ifndef CV_RGB2RGBA
#define CV_RGB2RGBA cv::COLOR_RGB2RGBA
#endif

#ifndef CV_RGB2BGR565
#define CV_RGB2BGR565 cv::COLOR_RGB2BGR565
#endif

#ifndef CV_RGBA2BGR
#define CV_RGBA2BGR cv::COLOR_RGBA2BGR
#endif

#ifndef CV_RGBA2GRAY
#define CV_RGBA2GRAY cv::COLOR_RGBA2GRAY
#endif

#ifndef CV_ADAPTIVE_THRESH_GAUSSIAN_C
#define CV_ADAPTIVE_THRESH_GAUSSIAN_C cv::ADAPTIVE_THRESH_GAUSSIAN_C
#endif

#ifndef CV_THRESH_BINARY
#define CV_THRESH_BINARY cv::THRESH_BINARY
#endif

#ifndef CV_BGR2HSV
#define CV_BGR2HSV cv::COLOR_BGR2HSV
#endif

#ifndef CV_BGR2Lab
#define CV_BGR2Lab cv::COLOR_BGR2Lab
#endif

#ifndef CV_RGB2HSV
#define CV_RGB2HSV cv::COLOR_RGB2HSV
#endif

#ifndef CV_HSV2RGB
#define CV_HSV2RGB cv::COLOR_HSV2RGB
#endif

#ifndef CV_THRESH_OTSU
#define CV_THRESH_OTSU cv::THRESH_OTSU
#endif


#ifndef CV_THRESH_BINARY
#define CV_THRESH_BINARY THRESH_BINARY
#endif

#ifndef CV_MOP_CLOSE
#define CV_MOP_CLOSE cv::MORPH_CLOSE
#endif

#ifndef CV_RETR_CCOMP
#define CV_RETR_CCOMP cv::RETR_CCOMP
#endif

#ifndef CV_RETR_LIST
#define CV_RETR_LIST cv::RETR_LIST
#endif

#ifndef CV_RETR_TREE
#define CV_RETR_TREE cv::RETR_TREE
#endif

#ifndef CV_RETR_FLOODFILL
#define CV_RETR_FLOODFILL cv::RETR_FLOODFILL
#endif

#ifndef CV_RETR_EXTERNAL
#define CV_RETR_EXTERNAL cv::RETR_EXTERNAL
#endif

#ifndef CV_CHAIN_APPROX_SIMPLE
#define CV_CHAIN_APPROX_SIMPLE cv::CHAIN_APPROX_SIMPLE
#endif

#ifndef CV_CHAIN_APPROX_TC89_KCOS
#define CV_CHAIN_APPROX_TC89_KCOS cv::CHAIN_APPROX_TC89_KCOS
#endif

#ifndef CV_FILLED
#define CV_FILLED cv::FILLED
#endif


#ifndef CV_REDUCE_SUM
#define CV_REDUCE_SUM cv::REDUCE_SUM
#endif

#ifndef CV_StsBadArg
#define CV_StsBadArg cv::Error::StsBadArg
#endif
//}

#ifndef cvFastArctan
#define cvFastArctan( Y, X ) ( std::atan2( (Y), (X) ) )
#endif

#endif //endif CV_MAJOR_VERSION

#endif //ANDROID_DOXCAPTUREUI_OPENCV4_COMPAT_H

Android NDK 是 switched从 NDK r16 版本开始到 LLVM 的 libc++。随着新的主要版本 4.0,OpenCV 也从 GNU 的 libstdc++ 切换到 libc++。如果您设置“-DANDRID_STL=gnuSTL_shared”,它将不起作用,因为默认的 OpenCV 二进制文件是使用 libc++ 而不是 gnuSTL 构建的。您应该在 build.gradle 文件中设置 cmake 参数“-DANDROID_STL=c++_shared”,如下所示:

    externalNativeBuild {
cmake {
//sample cpp flag parameters
cppFlags "-std=c++14 -Ofast -Rpass-analysis=loop-vectorize -fsave-optimization-record -fdiagnostics-show-hotness"
//sample abi filter parameters
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
//set -DANDROID_STL to c++_shared
arguments "-DANDROID_STL=c++_shared"
}
}

关于android - Android 中的 OpenCV 4.0.1 链接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54376290/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com