How to integrate OpenCV Manager in Android App

Yes. To integrate OpenCV inside your application, and avoid explicit installation of OpenCV manager, you need to first read following document provided by OpenCV.

First Read -> Static Initialization of OpenCV

After successfully followed steps, you need to write following code to enable OpenCV in your application initialization code before calling OpenCV API. It can be done, for example, in the static section of the Activity class:

static {
    if (!OpenCVLoader.initDebug()) {
        // Handle initialization error
    }
}

References:

  1. http://answers.opencv.org/question/2033/use-opencv-on-android-without-manager/
  2. Static Initialization on OpenCV Android

Edit

As per new scenario in Document and thanks to @rozhok for providing new information, initDebug() method can't be used for production build

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.

You need to use following method for that

Syntax

static boolean initAsync(String Version, Context AppContext, LoaderCallbackInterface Callback)

Example

public class Sample1Java extends Activity implements CvCameraViewListener {

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                    Log.i(TAG, "OpenCV loaded successfully");
                    mOpenCvCameraView.enableView();
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };

    @Override
    public void onResume()
    {
        super.onResume();
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback);
    }

    ...
}

References

  1. http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html

Tags:

Android

Opencv