1

I know this question has been asked and answered several times here. But none of these solutions works for me:

Here's my code (from this page):

package com.example.helloopencv;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceView;
import android.view.WindowManager;

public class HelloOpenCVActivity extends Activity implements CvCameraViewListener2 {

    protected static final String TAG = "HelloOpenCV";

    static {
        if (!OpenCVLoader.initDebug())
            Log.e(TAG, "Failed to load OpenCV!");
    }

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

    private CameraBridgeViewBase mOpenCvCameraView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "called onCreate");
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_hello_open_cv);
        mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.HelloOpenCVView);
        mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
        mOpenCvCameraView.setCvCameraViewListener(this);
    }

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

    @Override
    public void onPause()
    {
        super.onPause();
        if (mOpenCvCameraView != null)
            mOpenCvCameraView.disableView();
    }

    public void onDestroy() {
        super.onDestroy();
        if (mOpenCvCameraView != null)
            mOpenCvCameraView.disableView();
    }

    public void onCameraViewStarted(int width, int height) {
    }

    public void onCameraViewStopped() {
    }

    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        return inputFrame.rgba();
    }
}

I have also followed the settings here. However, every time I try to run the code in my device (Galaxy Note 2), I am always asked to install OpenCV Manager package. Could I have missed something? Anybody can help me?

Thanks!

Community
  • 1
  • 1
ArthurN
  • 179
  • 5
  • 15
  • possible duplicate of [How to integrate OpenCV Manager in Android App](http://stackoverflow.com/questions/20259309/how-to-integrate-opencv-manager-in-android-app) – kiranpradeep May 04 '15 at 04:45
  • Solution 4: http://stackoverflow.com/a/35135495/5611377 – ssimm May 14 '16 at 12:08
  • Possible duplicate of [OpenCV in Android Studio](http://stackoverflow.com/questions/27406303/opencv-in-android-studio) – ssimm May 14 '16 at 12:08

2 Answers2

10

Add

mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);

after mOpenCvCameraView.setCvCameraViewListener(this); in onCreate()

and remove OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback); from onResume()

If everything else is correctly done, this should not ask for OpenCV Manager.

EDIT :

it will be better if you put below code inside onResume method of your Activity

mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);

Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57
xMKx
  • 121
  • 4
  • Hello there, I have got the same problem but after I insert the line mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS) to my code I have got bunch of errors and my app crashed. The errors are ClassNotFoundException:com.googlecode.javacv.cpp.opencv_calib3d and same error on opencv_highgui library. Would you please help me? – A23149577 Jul 05 '14 at 05:41
  • 1
    Sorry for the delayed answer. If you still have the problem you should have to check if all of the required files are in the libs folder. For static initialization you need to have all of the .so files in the armeabi etc folders. I think it is mentioned also in the tutorial that opencv provided. – xMKx Jul 14 '14 at 08:41
  • 1
    it should be inside `onResume` to make it work when user moves out of the app and comes back. – Mehul Joisar Mar 13 '15 at 06:20
4

Copy all the library's files.

Or simply install the manager within the app like:

Intent promptInstall = new Intent(Intent.ACTION_VIEW)
    .setDataAndType(Uri.parse("file:///path/to/org.opencv.engine.v2.14.apk"), 
                    "application/vnd.android.package-archive");
startActivity(promptInstall); 

add this permission:

<uses-permission android:name="android.permission.INSTALL_PACKAGES" />