gpt4 book ai didi

android - 如何使用 NDK 为 OpenCV 引用 hpp 文件?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:45:23 25 4
gpt4 key购买 nike

我无法让我的项目打开 OpenCV 的头文件:

enter image description here

但是,通过在 onCreate() 中调用 OpenCVLoader.initDebug(),我可以看到 OpenCV 运行正常(如果我注释掉那些包含):

enter image description here

read你需要编辑 Android.mk 我一开始就没有。那我错过了什么?


编辑(3 小时后):

好的,所以我想出了如何包含 .hpp 文件,我将其添加到 CMakeLists.txt 的末尾:

include_directories("${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}/include/opencv"
"${CMAKE_SOURCE_DIR}/include/opencv2"
"${CMAKE_SOURCE_DIR}/include/opencv2/core"
"${CMAKE_SOURCE_DIR}/include/opencv2/features2d"
"${CMAKE_SOURCE_DIR}/include/opencv2/imgproc")

add_library(opencv_core STATIC IMPORTED)
set_target_properties(opencv_core PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt/libs/armeabi/libopencv_core.a)

add_library(opencv_imgproc STATIC IMPORTED)
set_target_properties(opencv_imgproc PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt/libs/armeabi/libopencv_imgproc.a)

add_library(opencv_features2d STATIC IMPORTED)
set_target_properties(opencv_features2d PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt/libs/armeabi/libopencv_features2d.a)

现在我在链接时收到undefined reference错误:

> Build command failed.
Error while executing 'C:\Users\kfjier\AppData\Local\Android\sdk\cmake\3.6.3155560\bin\cmake.exe' with arguments {--build E:\Dropbox\Freelance\BowlingOpenCV\Bowlingtrainer\app\.externalNativeBuild\cmake\debug\mips64 --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ..\obj\mips64\libnative-lib.so
FAILED: cmd.exe /C "cd . && C:\Users\kfjier\AppData\Local\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -target mips64el-none-linux-android -gcc-toolchain C:/Users/kfjier/AppData/Local/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/kfjier/AppData/Local/Android/sdk/ndk-bundle/platforms/android-21/arch-mips64 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\obj\mips64\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -lm "C:/Users/kfjier/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/mips64/libgnustl_static.a" && cd ."
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function `Java_eu_codehunter_bowlingtrainer_MainActivity_FindFeatures':
E:\Dropbox\Freelance\BowlingOpenCV\Bowlingtrainer\app\src\main\cpp/native-lib.cpp:18: undefined reference to `cv::FastFeatureDetector::create(int, bool, int)'
E:\Dropbox\Freelance\BowlingOpenCV\Bowlingtrainer\app\src\main\cpp/native-lib.cpp:19: undefined reference to `cv::noArray()'
E:\Dropbox\Freelance\BowlingOpenCV\Bowlingtrainer\app\src\main\cpp/native-lib.cpp:23: undefined reference to `cv::circle(cv::_InputOutputArray const&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

为什么?

最佳答案

我认为 cv::FastFeatureDetector 类属于 libopencv_features2d.a,而 cv::circle() 函数属于 libopencv_highgui.a。所以你必须包括那些图书馆。一种更简单的方法是添加单个 libopencv_java3.so 作为包含所有 OpenCV 库的共享库。

关于android - 如何使用 NDK 为 OpenCV 引用 hpp 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39816613/

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