Image manipulations sample updated for OpenCV Manager model.

pull/2/head
Alexander Smorkalov 13 years ago
parent a743eca076
commit 7a858885e6
  1. 53
      samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java

@ -1,5 +1,7 @@
package org.opencv.samples.imagemanipulations;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import android.app.Activity;
@ -36,6 +38,38 @@ public class ImageManipulationsActivity extends Activity {
public static int viewMode = VIEW_MODE_RGBA;
private ImageManipulationsView mView;
private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
// Create and set View
mView = new ImageManipulationsView(mAppContext);
setContentView(mView);
// Check native OpenCV camera
if( !mView.openCamera() ) {
AlertDialog ad = new AlertDialog.Builder(mAppContext).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("Fatal error: can't open camera!");
ad.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
});
ad.show();
}
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
public ImageManipulationsActivity() {
Log.i(TAG, "Instantiated new " + this.getClass());
@ -45,14 +79,15 @@ public class ImageManipulationsActivity extends Activity {
protected void onPause() {
Log.i(TAG, "onPause");
super.onPause();
mView.releaseCamera();
if (null != mView)
mView.releaseCamera();
}
@Override
protected void onResume() {
Log.i(TAG, "onResume");
super.onResume();
if( !mView.openCamera() ) {
if( (null != mView) && !mView.openCamera() ) {
AlertDialog ad = new AlertDialog.Builder(this).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("Fatal error: can't open camera!");
@ -72,16 +107,12 @@ public class ImageManipulationsActivity extends Activity {
Log.i(TAG, "onCreate");
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
/** Try to load OpenCV library **/
if (OpenCVLoader.initDebug())
{
mView = new ImageManipulationsView(this);
setContentView(mView);
}
else
Log.i(TAG, "Trying to load OpenCV library");
if (!OpenCVLoader.initAsync(OpenCVLoader.OPEN_CV_VERSION_2_4_0, this, mOpenCVCallBack))
{
Log.e(TAG, "OpenCV loading failed!");
finish();
Log.e(TAG, "Cannot connect to OpenCV Manager");
finish();
}
}

Loading…
Cancel
Save