merged Android samples
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
set(sample example-tutorial-3-native)
|
||||
|
||||
add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" SDK_TARGET 11 ${ANDROID_SDK_TARGET} NATIVE_DEPS opencv_features2d)
|
||||
if(BUILD_FAT_JAVA_LIB)
|
||||
set(native_deps opencv_java)
|
||||
else()
|
||||
set(native_deps opencv_features2d)
|
||||
endif()
|
||||
|
||||
add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET} NATIVE_DEPS ${native_deps})
|
||||
if(TARGET ${sample})
|
||||
add_dependencies(opencv_android_examples ${sample})
|
||||
endif()
|
||||
|
@@ -1,5 +1,9 @@
|
||||
package org.opencv.samples.tutorial3;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
@@ -10,6 +14,42 @@ import android.view.Window;
|
||||
public class Sample3Native extends Activity {
|
||||
private static final String TAG = "Sample::Activity";
|
||||
private Sample3View mView;
|
||||
|
||||
private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
|
||||
// Load native library after(!) OpenCV initialization
|
||||
System.loadLibrary("native_sample");
|
||||
|
||||
// Create and set View
|
||||
mView = new Sample3View(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 Sample3Native() {
|
||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||
@@ -19,14 +59,15 @@ public class Sample3Native 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!");
|
||||
@@ -46,7 +87,11 @@ public class Sample3Native extends Activity {
|
||||
Log.i(TAG, "onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
mView = new Sample3View(this);
|
||||
setContentView(mView);
|
||||
|
||||
if (!OpenCVLoader.initAsync(OpenCVLoader.OPEN_CV_VERSION_2_4_0, this, mOpenCVCallBack))
|
||||
{
|
||||
Log.e(TAG, "Cannot connect to OpenCV Manager");
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,9 +26,7 @@ class Sample3View extends SampleViewBase {
|
||||
mBitmap.recycle();
|
||||
mBitmap = null;
|
||||
}
|
||||
mRGBA = null;
|
||||
|
||||
|
||||
mRGBA = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,8 +41,4 @@ class Sample3View extends SampleViewBase {
|
||||
}
|
||||
|
||||
public native void FindFeatures(int width, int height, byte yuv[], int[] rgba);
|
||||
|
||||
static {
|
||||
System.loadLibrary("native_sample");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user