33

I am using OpenCV2.4.7 Library in my Android app. When app starts its goes to Google Play store for Application called OpenCV Manager. Is there any way to integrate this application in my Android apk because we already using OpenCV library so why app needs OpenCV Engine Again? Is Their any way to integrate this engine?

2
  • Hey did you find a solution which works for the production version? In the link in the accepted answer, it is stated, "It is designed mostly for development purposes. This approach is deprecated for the production code, release package is recommended to communicate with OpenCV Manager via..."
    – Solace
    Commented Dec 12, 2015 at 13:27
  • Here is a step by step way, with illustrations that show what you should get: stackoverflow.com/a/35135495/5611377
    – ssimm
    Commented May 14, 2016 at 11:58

4 Answers 4

26

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
19
  • 1
    docs.opencv.org/doc/tutorials/introduction/…
    – Tom A
    Commented Apr 18, 2015 at 14:19
  • 2
    Why this approach is not recommended for production usage (according to docs)? Commented Sep 21, 2015 at 6:57
  • 2
    Have you tried it? I've tried and it asks me to download OpenCV manager which is not acceptable for me. Commented Sep 28, 2015 at 17:49
  • 4
    @ChintanRathod: this approach (use async init) is devoted to call OpenCV manager if it wasn't found on device. So It is not a solution to 'bundle opencv into app'. I've tried good old deprecated way and it works fine. Commented Sep 30, 2015 at 7:19
  • 2
    So will this work on production apps with the initDebug method instead of the initAsync? I am finding conflicting information on this. I do not want my users to be prompted to install OpenCV Manager on running the app and would like to ship the app with all needed libraries and stuff. Does the initDebug work on production?
    – Devsil
    Commented Feb 9, 2016 at 15:12
0

This is what the documentation says about the OpenCV Manager installation:

apk folder contains Android packages that should be installed on the target Android device to enable OpenCV library access via OpenCV Manager API (see details below).

On production devices that have access to Google Play Market (and Internet) these packages will be installed from Market on the first start of an application using OpenCV Manager API.

...

Note: Installation from Internet is the preferable way since OpenCV team may publish updated versions of this packages on the Market.

You can read more about it here: https://docs.opencv.org/3.0-beta/doc/tutorials/introduction/android_binary_package/O4A_SDK.html#general-info

0
  1. Insert this lines after include $ (CLEAR_VARS) in OpenCV.mk file
    OPENCV_CAMERA_MODULES:=on
    OPENCV_INSTALL_MODULES:=on
    include D:/opencv_with/OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk
    
  2. In your current project directory libs folder copy all folder inside OpenCV libs.

  3. Add in your Activity

    if (!OpenCVLoader.initDebug()) {
                Log.d("ERROR", "Unable to load OpenCV");
            } else {
                mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
            }
    
    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    
            @Override
            public void onManagerConnected(int status) {
                switch (status) {
                case LoaderCallbackInterface.SUCCESS: {
    
                    //Your opencv Operation code
    
                }
                }
            }
        };
    
-6

Just comment the line in following Code

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

}

Not the answer you're looking for? Browse other questions tagged or ask your own question.