Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Opencv static initialization

Tags:

android

opencv

I am using OpenCV for Android in my app using static initialization. The code to initialize is -

static {
    if(!OpenCVLoader.initDebug()) {
        Log.d("My App", "Unable to load OpenCV");
    } else {
        Log.d("My App", "OpenCV loaded");
    }
}

Well this works fine. But in the OpenCV documentation it is specified that initDebug() is deprecated -

Note This method is deprecated for production code. It is designed for experimental and local development purposes only. If you want to publish your app use approach with async initialization.

Now if I use async initialization, it uses OpenCV manager app which should be installed on the device. This is not what I want.

My question is - If initDebug() is deprecated to use in release mode, is there any other way to load openCV which does not use OpenCV Manager? Or is it safe to load OpenCV using initDebug()?

like image 267
user1930106 Avatar asked Sep 02 '26 12:09

user1930106


1 Answers

My answer will be derived from my experience using that library!

OpenCVLoader.initDebug() iterates over some options to load the library into memory using System.loadLibrary("lib_name") at the end and trying to cover you with some logs!

from the OpenCVLoader.initDebug() method documentation

Loads and initializes OpenCV library from current application package. Roughly, it's an analog of System.loadLibrary("opencv_java").

So in the end, if you are going to use the statically loaded library which is more convenient in most cases because you don't want the user to install another application in order to use yours, you shall load the library into memory using System.loadLibrary("lib_name") to be able to use them in your java code and it won't really matter if you loaded it directly or using the initDebug helper method.

Note: New versions of the library have the version appended to the end of the library name so you shall use System.loadLibrary("opencv_java3") or whatever name you have as the name of the library in the jniLibs folder!

like image 112
Ahmed Hegazy Avatar answered Sep 05 '26 02:09

Ahmed Hegazy