Ask Your Question

Revision history [back]

OpenCv crashes when calling from android activity.

i have this code in which i use openCV to launch a camera. The code is given below. If this class "MainActivity" is used as the main class then every thing works fine but if i use it from another activity then the application crashes.

Here's the code of openCV android.

private CameraBridgeViewBase mOpenCvCameraView;

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_3, this,     mLoaderCallback);
     }

     @Override
        protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
         setContentView(R.layout.helloopencvlayout);
       mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.HelloOpenCvView);
      mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
         mOpenCvCameraView.setCvCameraViewListener((CvCameraViewListener2) this);

     }.

Now if i try to call this from another activity using intent in which i just have a button and onclick method is implemented and when the button is pressed , this activity is called , the application crashes.

It's been more the 4 hours , i am struggling with it. Please help and thanks in advance.

What i believe is that there is a callback method implemented , so we can't call this activity as normal activity call , or may be some other concept. I search it on the internet , but nothing helps. Some where i also found the concept of Async call , but i didn't get it.

Please help. Thanks.