我正在尝试使用 jni 和 Android Studio NDK 在 Android Studio 中进行 OpenCV C++ 调用。这些是我一直在工作的参考资料:
https://github.com/opencv/opencv/tree/master/samples/android/tutorial-2-mixedprocessing https://github.com/opencv/opencv/tree/master/samples/android/tutorial-2-mixedprocessing
https://codelabs.developers.google.com/codelabs/android-studio-jni/index.html?index=..%2F..%2Findex#0 https://codelabs.developers.google.com/codelabs/android-studio-jni/index.html?index=..%2F..%2Findex#0
http://hujiaweibujidao.github.io/blog/2014/10/22/android-ndk-and-opencv-development-with-android-studio/ http://hujiaweibujidao.github.io/blog/2014/10/22/android-ndk-and-opencv-development-with-android-studio/
https://blog.nishtahir.com/2015/11/11/setting-up-for-android-ndk-development/ https://blog.nishtahir.com/2015/11/11/setting-up-for-android-ndk-development/
http://kn-gloryo.github.io/Build_NDK_AndroidStudio_detail/ http://kn-gloryo.github.io/Build_NDK_AndroidStudio_detail/
https://www.youtube.com/watch?v=G0vL7-_xuDM https://www.youtube.com/watch?v=G0vL7-_xuDM
https://www.youtube.com/watch?v=RmPuwdxR1qs https://www.youtube.com/watch?v=RmPuwdxR1qs
Android NDK:如何让 gcc 使用额外的包含目录 https://stackoverflow.com/questions/7348997/android-ndk-how-to-let-gcc-to-use-additional-include-directories
在大多数情况下,我一直在尝试让第二个 OpenCV 示例(上面的第一个链接)在 Android Studio 中运行。这是迄今为止我得到的最接近的结果:
https://github.com/MicrocontrollersAndMore/OpenCVTestNative/tree/22895c5304c5fb7f0bd62c0f5eef494d3f0280f9 https://github.com/MicrocontrollersAndMore/OpenCVTestNative/tree/22895c5304c5fb7f0bd62c0f5eef494d3f0280f9
目前我收到错误:
C:\Users\Chris.Dahms\Documents\AndroidOpenCVCppProgs\OpenCVTestNative\app\src\main\jni\jni_part.cpp
Error:(2, 28) opencv2/core.hpp: No such file or directory
我已经尝试了上面链接中的所有内容,但均无济于事。
我应该提到的是,我可以让 Java OpenCV 调用在 Android Studio 中工作,基本上遵循这篇文章:
Android Studio 中的 OpenCV https://stackoverflow.com/questions/27406303/opencv-in-android-studio
但无论我做了什么,我都无法让 C++ jni 调用正常工作。我通过从项目向导开始,然后添加第二个 OpenCV for Android 示例中的部分来创建上述链接的 GitHub 项目:
https://github.com/opencv/opencv/tree/master/samples/android/tutorial-2-mixedprocessing https://github.com/opencv/opencv/tree/master/samples/android/tutorial-2-mixedprocessing
我尝试过的另一种方法是从以下位置下载 OpenCV 源代码:
https://github.com/opencv/opencv https://github.com/opencv/opencv
然后解压并使用Android Studio“导入项目(Eclipse ADT、Gradle等)”选项。导入后我收到消息
我已经阅读了实验性插件,这似乎不是推荐的方法,所以我选择
Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration
选项,其中包含以下行:
android.useDeprecatedNdk=true
在 gradle.properties 的末尾。之后我收到很多错误,但是如果我按照以下步骤操作
Android Studio 中的 OpenCV https://stackoverflow.com/questions/27406303/opencv-in-android-studio
再次,这让我回到原来的状态
Error:(2, 28) opencv2/core.hpp: No such file or directory
这是我的屏幕的样子:
如果查看源代码会有帮助的话,这是该项目:
https://github.com/MicrocontrollersAndMore/tutorial-2-mixedprocessing https://github.com/MicrocontrollersAndMore/tutorial-2-mixedprocessing
有人真的让它发挥作用了吗?我看到一些帖子暗示这是可能的,但我找不到任何具体说明。任何在这方面取得成功的人都可以与我们其他人分享吗?
编辑:
有人建议这是一个答案:
Android Studio 与 opencv for android ndk,未找到 opencv 头文件 https://stackoverflow.com/questions/29214015/android-studio-with-opencv-for-android-ndk-opencv-header-files-not-found
虽然这确实让我克服了 opencv2/core.hpp: No such file or directory 错误,但在 Android Studio 中,FindFeatures 调用仍然显示为红色,就好像 Java 文件看不到 C++ 文件一样:
在应用程序的 build.gradle 文件中,多行有下划线错误:
还有什么进一步的建议吗?
进一步编辑:
我忘了提及,我在 build.gradle 中遇到了下划线错误,并且在默认括号之外还添加了以下内容:
当我运行该应用程序时,它因错误而崩溃
couldn't find "libmixed_sample.so"
在 LogCat 和手机上出现“不幸的是应用程序已停止”错误
还有进一步的建议吗?