Ask Your Question
0

OpenCVLoader.initAsync() fails for the first few times

asked 2017-09-20 05:00:07 -0600

xzx gravatar image

updated 2017-09-20 05:38:25 -0600

OpenCV 3.3.0 Android 7.1.1 Oneplus 5

I installed OpenCV 3.3.0 Manager arm64-v8a by adb to the phone. The OpenCVLoader.initAsync() operation always fails for the first few times, and succeeds finally.

A "Package not found" dialog shows. I click "NO". Repeat this several times. And then succeeds.

Load code is:

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

logcat output:

09-20 17:49:51.577 17807-17807/cn.deepclue.vins2 I/Vins2Tag: In onCreate()
09-20 17:49:51.583 17807-17807/cn.deepclue.vins2 D/CameraBridge: Attr count: 6
09-20 17:49:51.592 17807-17807/cn.deepclue.vins2 D/OpenCVManager/Helper: Request new service installation
09-20 17:49:51.605 17807-22993/cn.deepclue.vins2 D/AppTracker: App Event: start
09-20 17:49:51.640 17807-17807/cn.deepclue.vins2 D/CameraBridge: call surfaceChanged event
09-20 17:49:51.640 17807-17807/cn.deepclue.vins2 D/CameraBridge: call checkCurrentState

Please give me some clue to solve this issue.

The complete code is:

public class MainActivity extends Activity implements CvCameraViewListener2 {
private static final String TAG = "Vins2Tag";

private CameraBridgeViewBase cameraView;

// Used to load the 'native-lib' library on application startup.
static {
    System.loadLibrary("native-lib");
}

private BaseLoaderCallback loaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        if (status == LoaderCallbackInterface.SUCCESS) {
            Log.i(TAG, "OpenCV loaded successfully");
            cameraView.enableView();
        } else {
            Log.i(TAG, "OpenCV load failed");
        }

        super.onManagerConnected(status);
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "In onCreate()");

    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_main);

    cameraView = (CameraBridgeViewBase) findViewById(R.id.camera_view);

    cameraView.setVisibility(SurfaceView.VISIBLE);

    cameraView.setCvCameraViewListener(this);
}

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

@Override
public void onResume() {
    Log.i(TAG, "In onResume()");
    super.onResume();
    Log.d(TAG, "Using OpenCV Manager for initialization");
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_3_0, this, loaderCallback);

}

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

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

public void onCameraViewStopped() {
}

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

/**
 * A native method that is implemented by the 'native-lib' native library,
 * which is packaged with this application.
 */
public native String stringFromJNI();
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-09-26 00:41:59 -0600

xzx gravatar image

I flashed lineageos and the problem went away.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-09-20 05:00:07 -0600

Seen: 496 times

Last updated: Sep 26 '17