Ask Your Question
0

Hello OpenCV is not working

asked 2013-08-19 09:03:22 -0600

anushkamahesh gravatar image

updated 2013-08-19 09:04:58 -0600

I am new guy to android OpenCv, so i started with referring to this tutorial given OpenCV doc in this link i have followed steps same as given in the description but the app does't work it and end up with "Unfortunately, Helloworld has stopped" and here is my code of Mainactivity class generated by eclipse with fixing errors

public class MainActivity extends Activity {
private static final String TAG = "OCVSample::Activity";
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_main);
    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.HelloOpenCvView);
    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
    mOpenCvCameraView.setCvCameraViewListener((CvCameraViewListener2) this);
}

@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();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

public BaseLoaderCallback getMloadBaseLoaderCallback() {
    return mloadBaseLoaderCallback;
}

public void setMloadBaseLoaderCallback(
        BaseLoaderCallback mloadBaseLoaderCallback) {
    this.mloadBaseLoaderCallback = mloadBaseLoaderCallback;
}

private BaseLoaderCallback mloadBaseLoaderCallback = 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_5, this,
            getMloadBaseLoaderCallback());
}

}

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-08-19 10:07:43 -0600

berak gravatar image

there are some things broken here.

first it has to be:

public class MainActivity extends Activity  implements CvCameraViewListener2 {

then, it should be:

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

i.e, you don't need the set/get methods for this

edit flag offensive delete link more

Comments

Thnx.it works

anushkamahesh gravatar imageanushkamahesh ( 2013-08-20 01:17:11 -0600 )edit

Question Tools

Stats

Asked: 2013-08-19 09:03:22 -0600

Seen: 886 times

Last updated: Aug 19 '13