使用适用于Android的OpenCv contrib模块 [英] Using OpenCv contrib modules for android

查看:252
本文介绍了使用适用于Android的OpenCv contrib模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在Android中使用opencv contrib模块?我专门使用文本模块.这些模块是否有android lib.我的代码在台式机上工作,我正尝试将代码迁移到android.任何见识都会是gr8.

Is there a way to use opencv contrib modules in android ? I am specifically using text module. Is there a android lib for these modules. I have my code working on desktop and i m trying to migrate my codes to android. Any insight would be gr8.

推荐答案

我也在寻找解决这些问题的方法时遇到了问题.我想我会在那里找到一个相关的问题,并为社区做出回应,以防其他人也在寻找与这个问题和我的问题类似的解决方案.编译是在Macbook Retina 13上完成的.

I was having issues figuring out solutions to these problems as well. I thought I would find a relevant question out there and put a response in for the community in case others are also looking for solutions to a problem similar to this one and mine. Compilation was done on a Macbook Retina 13".

提供的说明有些不完整,最终产品还需要其他步骤.

The instructions provided are somewhat incomplete and there are additional steps that will be needed to get to a final product.

开始时,您将遵循在线概述的标准程序

At the start you will follow the standard procedure as outlined online

$ cd <opecv_directory>
$ mkdir build
$ cd <opencv_build_directory>
$ cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
$ make -j5
$ make install

除此之外,您可能会遇到一个或两个错误.我需要安装一些缺少的组件才能获得过去丢失的东西,但这可能对您有所不同(我研究了错误并了解到我需要其他组件)

In addition to this, you may run across an error or two. I needed to install some missing components in order to get past things that were missing but this may differ for you (I researched errors and understood that I needed additional components)

brew install ninja
brew install oxygen
brew install ant

我还遇到一个错误,一个模块请求在源代码中声明以下内容(或带有编译器标志):

I also ran into an error with one module requesting the need for the following declared in the source code (or with compiler flags):

#define SOLARIS_64BIT_ENABLED

您可以做的另一件事是删除contrib文件夹中的其他模块,这些模块在编译过程中可能不会引起您的兴趣.只需包含您想要的模块,并希望这些模块是好的.我只是通过从/modules文件夹中删除一两个来执行此操作,然后重新运行python脚本.

Another thing you can do is remove other modules in the contrib folder you may not be interested in during compilation. Just include the modules you want and hopefully those ones are good. I did this simply by removing one or two from the /modules folder and then reran the python script.

需要一个最终的python脚本来运行构建.我在主源代码树和contrib文件夹旁边创建了一个目录.

A final python script was needed to run the build. I created a directory alongside the main source tree and contrib folder.

OpenCVSource
  -> opencv
  -> opencv_contrib
  -> android_opencv_build

下面的调用是从我要进行构建的目录中进行的,因此我更改为目录.调用如下:

The call below was made from the directory where I want the build to be taking place from, so I changed to the directory The call was the following:

python ../opencv/platforms/android/build_sdk.py --extra_modules_path ../opencv_contrib/modules --ndk_path <your-path-to-ndk-top-level-folder> --sdk_path <your-path-to-sdk-top-level-folder> ./ ../opencv

这只会生成使用该库所需的.so文件,但不会生成使用新二进制文件所需的.jar文件.为此,请导航至您的构建文件夹(如所见,位于android_opencv_build/OpenCV-android-sdk中)

This only builds the .so files that are necessary for using the library, but it doesn't build the .jar file that you will need to use the new binaries. In order to do that navigate to your build folder (mine as seen is in android_opencv_build/OpenCV-android-sdk)

以标准方式将此项目加载到Eclipse中,并将现有的Android项目导入工作区中.您实际上只需要/sdk项目,但也可以根据需要随意加载样本.然后构建项目.您可能需要更改目标构建,以支持新的Camera API才能成功构建.在我的情况下,将目标更改为API级别21.

Load this project into Eclipse in the standard manner with the import existing Android project into workspace. You really only need the /sdk project but feel free to load samples as well if desired. Then build the project. You may need to alter the target build to support the new Camera APIs for a successful build; in my case changing the target to API level 21.

然后您将在项目的/bin目录中找到.jar文件.在android_opencv_build/OpenCV-android-sdk/sdk/native/jni/中找到的.jar文件和.so文件包含必要的.so文件,您需要将该文件与该jar文件一起放在项目/lib文件夹中.

You will then find the .jar file in the /bin directory of the project. The .jar and the .so files found in android_opencv_build/OpenCV-android-sdk/sdk/native/jni/ contain the necessary .so files that you will need to include in your projects /lib folder alongside this jar.

现在您应该拥有所需的一切.由于我们正在使用contrib模块(或者如果您出于其他原因而无法构建模块),则可能会遇到构建过程中不稳定的其他错误,需要引起注意.这无济于事,但是人们可以随时向其他人的解决方案添加评论,如果发现了解决方案,则可以通过这篇文章来帮助他们解决问题.

Now you should have everything that you need. Since we are working with contrib modules (or not if you are building it for other reasons), it is possible that you will run across other errors in the build process that are not quite stable and will need some attention. This cannot be helped but people can feel free to add comments to other peoples solutions and this post to aide them in resolving them if they have found a solution.

这篇关于使用适用于Android的OpenCv contrib模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆