在Android 5.0(棒棒糖)上使用OpenCV for Android的问题

时间:2015-03-07 00:13:20

标签: android opencv android-5.0-lollipop

首先,没有一个OpenCV示例适用于Nexus 6 Android 5.0。在OpenCV管理器安装提示后,我看到一个屏幕,显示找不到项目,重试'。我后来设置了android studio并导入了opencv模块并编写了一个初始化OpenCV的基本程序。该应用程序崩溃抛出了这篇文章中提到的错误:OpenCV Service Intent must be explicit, Android 5.0 Lolipop。按照建议后,我得到了下载OpenCV管理器的提示并成功安装了OpenCV管理器。但是当我返回应用程序时,我发现它无法获得库路径。 logcat反复显示这些消息 -

 W/ContextImpl﹕ Implicit intents with startService are not safe: Intent { act=org.opencv.engine.BIND } android.content.ContextWrapper.bindService:538 org.opencv.android.AsyncServiceHelper.initOpenCV:24 org.opencv.android.OpenCVLoader.initAsync:44
 D/OpenCVManager/Helper﹕ Service connection created
 D/OpenCVManager/Helper﹕ Trying to get library path
 W/ContextImpl﹕ Implicit intents with startService are not safe: Intent { act=org.opencv.engine.BIND } android.content.ContextWrapper.bindService:538 org.opencv.android.AsyncServiceHelper.initOpenCV:24 org.opencv.android.OpenCVLoader.initAsync:44
 D/OpenCVManager/Helper﹕ Service connection created
 D/OpenCVManager/Helper﹕ Trying to get library path

如何解决此问题并开始在Lollipop上使用OpenCV for Android?

2 个答案:

答案 0 :(得分:5)

我看到的最佳解决方法是在未提交官方修复时自行更新OpenCV的AsyncServiceHelper

你只需要添加一行。这很简单。

查找initOpenCV函数并将其更改为:

public static boolean initOpenCV(String Version, final Context AppContext,
    final LoaderCallbackInterface Callback) {
    AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext,
            Callback);
    Intent intent = new Intent("org.opencv.engine.BIND");
    intent.setPackage("org.opencv.engine");
    if (AppContext.bindService(intent, helper.mServiceConnection,
            Context.BIND_AUTO_CREATE)) {
        return true;
    } else {
        AppContext.unbindService(helper.mServiceConnection);
        InstallService(AppContext, Callback);
        return false;
    }
}

希望能提供帮助。

答案 1 :(得分:2)

我找到了一个临时解决方案。我调试了'AsyncServiceHelper'类。

未能获得路径
String path = mEngineService.getLibPathByVersion(mOpenCVersion); 

所以,我对下面的路径字符串进行了硬编码,现在我的Nexus 6已准备好运行使用OpenCV的程序

String path = "/data/data/org.opencv.engine/lib";