Issue with OpenCV for Android on Android 5.0 (loll

2019-01-20 01:46发布

问题:

First of all, none of the OpenCV samples work on Nexus 6 Android 5.0. After the OpenCV manager installation prompt, I get a screen that says 'Item not found, retry'. I later setup android studio and imported opencv module and wrote a basic program that initializes OpenCV. The app crashes throwing an error mentioned in this post : OpenCV Service Intent must be explicit, Android 5.0 Lolipop . After following the suggestions, I was able to get a prompt for downloading OpenCV manager and successfully installed OpenCV manager. But when I return to the application, I see that it fails to get library path. logcat shows these messages repeatedly-

 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

How do I get over this issue and start working on OpenCV for Android on Lollipop?

回答1:

The best workaround I saw is to update the OpenCV's AsyncServiceHelper by yourself while they don't commit a official fix.

You just have to add one line. It's very simple.

Look for initOpenCV function and change it to be like that:

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;
    }
}

Hope to help.



回答2:

I found a temporary fix for this. I debugged the 'AsyncServiceHelper' class. It is failing to obtain path at

String path = mEngineService.getLibPathByVersion(mOpenCVersion); 

So, I hard coded the path string like below and my Nexus 6 is now ready to run my program which uses OpenCV

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