简体   繁体   English

从Android中的本机c ++文件调用本机opencv

[英]Calling native opencv, from native c++ files in Android

really struggling here. 真的在这里挣扎。 Basically, I have a whole bunch of c++ files from an iOS project that use opencv and work fine. 基本上,我有来自iOS项目的大量c ++文件,这些文件使用opencv并且可以正常工作。

Now, I'm trying to port to Android. 现在,我正在尝试移植到Android。 So what I need to be able to do is, pull the existing c++ files that I have into the Android project as a shared library, and still be able to call the native opencv c++ methods. 因此,我需要做的是,将我已有的现有c ++文件作为共享库拉到Android项目中,并且仍然能够调用本机opencv c ++方法。 Is this possible? 这可能吗?

I know the java implementation is just a bunch of wrappers over the c++ code but I can't seem to find a way to call the native c++ code from other c++ files in the project. 我知道Java实现只是对c ++代码的一堆包装,但是我似乎找不到从项目中其他c ++文件调用本机c ++代码的方法。 Any help is appreciated. 任何帮助表示赞赏。 Thanks 谢谢

Steve 史蒂夫

Have you tried using Android NDK (Native Development Kit) ? 您是否尝试过使用Android NDK(本机开发套件) It allows you to use c/c++ code in Android. 它允许您在Android中使用c / c ++代码。 But you cannot simply import the library into your app, you need to build it using NDK (the .SO file) and it will generates script which act as linker to the code. 但是您不能简单地将库导入到您的应用中,您需要使用NDK(.SO文件)进行构建,它会生成脚本,用作脚本的链接器。

If I understand you correctly, you need to interface to opencv at the native layer (not through a Java API). 如果我对您的理解正确,则需要在本机层连接到opencv(而不是通过Java API)。 You should be able to grab the .so library for your target platform along with necessary headers and build against it using the NDK. 您应该能够获取目标平台的.so库以及必要的头文件,并使用NDK对其进行构建。

If your application project doesn't have a JNI part, just copy the corresponding OpenCV native libs from /sdk/native/libs/ to your project directory to folder libs/. 如果您的应用程序项目没有JNI部分,只需将相应的OpenCV本机libs从/ sdk / native / libs /复制到您的项目目录中的文件夹libs /中。

source 资源

There are many ways to set up an NDK build. 有许多方法可以设置NDK。 The more recent versions of CMake (>=3.7.2) make it relatively painless to cross compile. 较新版本的CMake(> = 3.7.2)使交叉编译变得相对轻松。 See this page 看到这个页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM