i am using opencv in android. but when i am adding Mat() in my code my application unexpectedly stops after launch. my error log is as below:
FATAL EXCEPTION
its good that someone prompted me to post my answer elaborately. so here i am posting the solution of my question :
private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
startDisplay();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "Trying to load OpenCV library");
if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mOpenCVCallBack))
{
Log.e(TAG, "Cannot connect to OpenCV Manager");
}
else{ Log.i(TAG, "opencv successfull");
System.out.println(java.lang.Runtime.getRuntime().maxMemory()); }
setContentView(R.layout.frameview);
}
The problem behind this error is that we are calling opencv dependent function(for example: Mat()) before opencv initialization so its showing error. So you can solve it if you put your opencv function in onManagerConnected() like this :
Log.i(TAG, "OpenCV loaded successfully");
startDisplay();
here, startDisplay() contains my Mat() initialization. The problem is when we start an app then oncreate() function executes first and after that opencv is loaded, so if you put your opencv function in oncreate() then it will show error as opencv is not yet loaded.
I hope this will solve your problem. Best of luck... Stackoverflow Rocks!!! :)