merged Android samples
This commit is contained in:
parent
162f9fd7ea
commit
2dcb091d94
@ -1,5 +1,9 @@
|
|||||||
package org.opencv.samples.colorblobdetect;
|
package org.opencv.samples.colorblobdetect;
|
||||||
|
|
||||||
|
import org.opencv.android.BaseLoaderCallback;
|
||||||
|
import org.opencv.android.LoaderCallbackInterface;
|
||||||
|
import org.opencv.android.OpenCVLoader;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@ -12,6 +16,38 @@ public class ColorBlobDetectionActivity extends Activity {
|
|||||||
private static final String TAG = "Example/ColorBlobDetection";
|
private static final String TAG = "Example/ColorBlobDetection";
|
||||||
private ColorBlobDetectionView mView;
|
private ColorBlobDetectionView 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 ColorBlobDetectionView(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 ColorBlobDetectionActivity()
|
public ColorBlobDetectionActivity()
|
||||||
{
|
{
|
||||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||||
@ -21,6 +57,7 @@ public class ColorBlobDetectionActivity extends Activity {
|
|||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
Log.i(TAG, "onPause");
|
Log.i(TAG, "onPause");
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
if (null != mView)
|
||||||
mView.releaseCamera();
|
mView.releaseCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +65,7 @@ public class ColorBlobDetectionActivity extends Activity {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
Log.i(TAG, "onResume");
|
Log.i(TAG, "onResume");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if( !mView.openCamera() ) {
|
if( (null != mView) && !mView.openCamera() ) {
|
||||||
AlertDialog ad = new AlertDialog.Builder(this).create();
|
AlertDialog ad = new AlertDialog.Builder(this).create();
|
||||||
ad.setCancelable(false); // This blocks the 'BACK' button
|
ad.setCancelable(false); // This blocks the 'BACK' button
|
||||||
ad.setMessage("Fatal error: can't open camera!");
|
ad.setMessage("Fatal error: can't open camera!");
|
||||||
@ -47,8 +84,14 @@ public class ColorBlobDetectionActivity extends Activity {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
Log.i(TAG, "onCreate");
|
Log.i(TAG, "onCreate");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
mView = new ColorBlobDetectionView(this);
|
|
||||||
setContentView(mView);
|
Log.i(TAG, "Trying to load OpenCV library");
|
||||||
|
if (!OpenCVLoader.initAsync(OpenCVLoader.OPEN_CV_VERSION_2_4_0, this, mOpenCVCallBack))
|
||||||
|
{
|
||||||
|
Log.e(TAG, "Cannot connect to OpenCV Manager");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,5 +4,5 @@ call android update project --target android-11 --library ../../OpenCV-2.4.1/ --
|
|||||||
call android update project --target android-11 --name "Tutorial 0 (Basic) - Android Camera" --path ./tutorial-0-androidcamera
|
call android update project --target android-11 --name "Tutorial 0 (Basic) - Android Camera" --path ./tutorial-0-androidcamera
|
||||||
call android update project --target android-11 --library ../../OpenCV-2.4.1/ --name "Tutorial 1 (Basic) - Add OpenCV" --path ./tutorial-1-addopencv
|
call android update project --target android-11 --library ../../OpenCV-2.4.1/ --name "Tutorial 1 (Basic) - Add OpenCV" --path ./tutorial-1-addopencv
|
||||||
call android update project --target android-11 --library ../../OpenCV-2.4.1/ --name "Tutorial 2 (Basic) - Use OpenCV Camera" --path ./tutorial-2-opencvcamera
|
call android update project --target android-11 --library ../../OpenCV-2.4.1/ --name "Tutorial 2 (Basic) - Use OpenCV Camera" --path ./tutorial-2-opencvcamera
|
||||||
call android update project --target android-11 --name "Tutorial 3 (Advanced) - Add Native OpenCV" --path ./tutorial-3-native
|
call android update project --target android-11 --library ../../OpenCV-2.4.1/ --name "Tutorial 3 (Advanced) - Add Native OpenCV" --path ./tutorial-3-native
|
||||||
call android update project --target android-11 --library ../../OpenCV-2.4.1/ --name "Tutorial 4 (Advanced) - Mix Java+Native OpenCV" --path ./tutorial-4-mixed
|
call android update project --target android-11 --library ../../OpenCV-2.4.1/ --name "Tutorial 4 (Advanced) - Mix Java+Native OpenCV" --path ./tutorial-4-mixed
|
@ -4,7 +4,7 @@ android update project --target android-11 --library ../../OpenCV-2.4.0/ --name
|
|||||||
android update project --target android-11 --name "Tutorial 0 (Basic) - Android Camera" --path ./tutorial-0-androidcamera
|
android update project --target android-11 --name "Tutorial 0 (Basic) - Android Camera" --path ./tutorial-0-androidcamera
|
||||||
android update project --target android-11 --library ../../OpenCV-2.4.0/ --name "Tutorial 1 (Basic) - Add OpenCV" --path ./tutorial-1-addopencv
|
android update project --target android-11 --library ../../OpenCV-2.4.0/ --name "Tutorial 1 (Basic) - Add OpenCV" --path ./tutorial-1-addopencv
|
||||||
android update project --target android-11 --library ../../OpenCV-2.4.0/ --name "Tutorial 2 (Basic) - Use OpenCV Camera" --path ./tutorial-2-opencvcamera
|
android update project --target android-11 --library ../../OpenCV-2.4.0/ --name "Tutorial 2 (Basic) - Use OpenCV Camera" --path ./tutorial-2-opencvcamera
|
||||||
android update project --target android-11 --name "Tutorial 3 (Advanced) - Add Native OpenCV" --path ./tutorial-3-native
|
android update project --target android-11 --library ../../OpenCV-2.4.0/ --name "Tutorial 3 (Advanced) - Add Native OpenCV" --path ./tutorial-3-native
|
||||||
android update project --target android-11 --library ../../OpenCV-2.4.0/ --name "Tutorial 4 (Advanced) - Mix Java+Native OpenCV" --path ./tutorial-4-mixed
|
android update project --target android-11 --library ../../OpenCV-2.4.0/ --name "Tutorial 4 (Advanced) - Mix Java+Native OpenCV" --path ./tutorial-4-mixed
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.opencv.samples.imagemanipulations;
|
package org.opencv.samples.imagemanipulations;
|
||||||
|
|
||||||
|
import org.opencv.android.BaseLoaderCallback;
|
||||||
|
import org.opencv.android.LoaderCallbackInterface;
|
||||||
import org.opencv.android.OpenCVLoader;
|
import org.opencv.android.OpenCVLoader;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -37,6 +39,38 @@ public class ImageManipulationsActivity extends Activity {
|
|||||||
|
|
||||||
private ImageManipulationsView mView;
|
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() {
|
public ImageManipulationsActivity() {
|
||||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||||
}
|
}
|
||||||
@ -45,6 +79,7 @@ public class ImageManipulationsActivity extends Activity {
|
|||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
Log.i(TAG, "onPause");
|
Log.i(TAG, "onPause");
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
if (null != mView)
|
||||||
mView.releaseCamera();
|
mView.releaseCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +87,7 @@ public class ImageManipulationsActivity extends Activity {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
Log.i(TAG, "onResume");
|
Log.i(TAG, "onResume");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if( !mView.openCamera() ) {
|
if( (null != mView) && !mView.openCamera() ) {
|
||||||
AlertDialog ad = new AlertDialog.Builder(this).create();
|
AlertDialog ad = new AlertDialog.Builder(this).create();
|
||||||
ad.setCancelable(false); // This blocks the 'BACK' button
|
ad.setCancelable(false); // This blocks the 'BACK' button
|
||||||
ad.setMessage("Fatal error: can't open camera!");
|
ad.setMessage("Fatal error: can't open camera!");
|
||||||
@ -72,15 +107,11 @@ public class ImageManipulationsActivity extends Activity {
|
|||||||
Log.i(TAG, "onCreate");
|
Log.i(TAG, "onCreate");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
/** Try to load OpenCV library **/
|
|
||||||
if (OpenCVLoader.initDebug())
|
Log.i(TAG, "Trying to load OpenCV library");
|
||||||
|
if (!OpenCVLoader.initAsync(OpenCVLoader.OPEN_CV_VERSION_2_4_0, this, mOpenCVCallBack))
|
||||||
{
|
{
|
||||||
mView = new ImageManipulationsView(this);
|
Log.e(TAG, "Cannot connect to OpenCV Manager");
|
||||||
setContentView(mView);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.e(TAG, "OpenCV loading failed!");
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package org.opencv.samples.tutorial1;
|
package org.opencv.samples.tutorial1;
|
||||||
|
|
||||||
|
import org.opencv.android.BaseLoaderCallback;
|
||||||
|
import org.opencv.android.LoaderCallbackInterface;
|
||||||
|
import org.opencv.android.OpenCVLoader;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@ -17,6 +21,38 @@ public class Sample1Java extends Activity {
|
|||||||
private MenuItem mItemPreviewCanny;
|
private MenuItem mItemPreviewCanny;
|
||||||
private Sample1View mView;
|
private Sample1View 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 Sample1View(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 Sample1Java() {
|
public Sample1Java() {
|
||||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||||
}
|
}
|
||||||
@ -25,6 +61,7 @@ public class Sample1Java extends Activity {
|
|||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
Log.i(TAG, "onPause");
|
Log.i(TAG, "onPause");
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
if (null != mView)
|
||||||
mView.releaseCamera();
|
mView.releaseCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +69,7 @@ public class Sample1Java extends Activity {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
Log.i(TAG, "onResume");
|
Log.i(TAG, "onResume");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if( !mView.openCamera() ) {
|
if( (null != mView) && !mView.openCamera() ) {
|
||||||
AlertDialog ad = new AlertDialog.Builder(this).create();
|
AlertDialog ad = new AlertDialog.Builder(this).create();
|
||||||
ad.setCancelable(false); // This blocks the 'BACK' button
|
ad.setCancelable(false); // This blocks the 'BACK' button
|
||||||
ad.setMessage("Fatal error: can't open camera!");
|
ad.setMessage("Fatal error: can't open camera!");
|
||||||
@ -52,8 +89,13 @@ public class Sample1Java extends Activity {
|
|||||||
Log.i(TAG, "onCreate");
|
Log.i(TAG, "onCreate");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
mView = new Sample1View(this);
|
|
||||||
setContentView(mView);
|
Log.i(TAG, "Trying to load OpenCV library");
|
||||||
|
if (!OpenCVLoader.initAsync(OpenCVLoader.OPEN_CV_VERSION_2_4_0, this, mOpenCVCallBack))
|
||||||
|
{
|
||||||
|
Log.e(TAG, "Cannot connect to OpenCV Manager");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package org.opencv.samples.tutorial2;
|
package org.opencv.samples.tutorial2;
|
||||||
|
|
||||||
|
import org.opencv.android.BaseLoaderCallback;
|
||||||
|
import org.opencv.android.LoaderCallbackInterface;
|
||||||
|
import org.opencv.android.OpenCVLoader;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@ -24,6 +28,38 @@ public class Sample2NativeCamera extends Activity {
|
|||||||
|
|
||||||
private Sample2View mView;
|
private Sample2View 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 Sample2View(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 Sample2NativeCamera() {
|
public Sample2NativeCamera() {
|
||||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||||
}
|
}
|
||||||
@ -32,6 +68,7 @@ public class Sample2NativeCamera extends Activity {
|
|||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
Log.i(TAG, "onPause");
|
Log.i(TAG, "onPause");
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
if (null != mView)
|
||||||
mView.releaseCamera();
|
mView.releaseCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +76,7 @@ public class Sample2NativeCamera extends Activity {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
Log.i(TAG, "onResume");
|
Log.i(TAG, "onResume");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if( !mView.openCamera() ) {
|
if((null != mView) && !mView.openCamera() ) {
|
||||||
AlertDialog ad = new AlertDialog.Builder(this).create();
|
AlertDialog ad = new AlertDialog.Builder(this).create();
|
||||||
ad.setCancelable(false); // This blocks the 'BACK' button
|
ad.setCancelable(false); // This blocks the 'BACK' button
|
||||||
ad.setMessage("Fatal error: can't open camera!");
|
ad.setMessage("Fatal error: can't open camera!");
|
||||||
@ -59,8 +96,12 @@ public class Sample2NativeCamera extends Activity {
|
|||||||
Log.i(TAG, "onCreate");
|
Log.i(TAG, "onCreate");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
mView = new Sample2View(this);
|
Log.i(TAG, "Trying to load OpenCV library");
|
||||||
setContentView(mView);
|
if (!OpenCVLoader.initAsync(OpenCVLoader.OPEN_CV_VERSION_2_4_0, this, mOpenCVCallBack))
|
||||||
|
{
|
||||||
|
Log.e(TAG, "Cannot connect to OpenCV Manager");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
set(sample example-tutorial-3-native)
|
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})
|
if(TARGET ${sample})
|
||||||
add_dependencies(opencv_android_examples ${sample})
|
add_dependencies(opencv_android_examples ${sample})
|
||||||
endif()
|
endif()
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package org.opencv.samples.tutorial3;
|
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.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@ -11,6 +15,42 @@ public class Sample3Native extends Activity {
|
|||||||
private static final String TAG = "Sample::Activity";
|
private static final String TAG = "Sample::Activity";
|
||||||
private Sample3View mView;
|
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() {
|
public Sample3Native() {
|
||||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||||
}
|
}
|
||||||
@ -19,6 +59,7 @@ public class Sample3Native extends Activity {
|
|||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
Log.i(TAG, "onPause");
|
Log.i(TAG, "onPause");
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
if (null != mView)
|
||||||
mView.releaseCamera();
|
mView.releaseCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +67,7 @@ public class Sample3Native extends Activity {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
Log.i(TAG, "onResume");
|
Log.i(TAG, "onResume");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if( !mView.openCamera() ) {
|
if((null != mView) && !mView.openCamera() ) {
|
||||||
AlertDialog ad = new AlertDialog.Builder(this).create();
|
AlertDialog ad = new AlertDialog.Builder(this).create();
|
||||||
ad.setCancelable(false); // This blocks the 'BACK' button
|
ad.setCancelable(false); // This blocks the 'BACK' button
|
||||||
ad.setMessage("Fatal error: can't open camera!");
|
ad.setMessage("Fatal error: can't open camera!");
|
||||||
@ -46,7 +87,11 @@ public class Sample3Native extends Activity {
|
|||||||
Log.i(TAG, "onCreate");
|
Log.i(TAG, "onCreate");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,6 @@ class Sample3View extends SampleViewBase {
|
|||||||
mBitmap = null;
|
mBitmap = null;
|
||||||
}
|
}
|
||||||
mRGBA = null;
|
mRGBA = null;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,8 +41,4 @@ class Sample3View extends SampleViewBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public native void FindFeatures(int width, int height, byte yuv[], int[] rgba);
|
public native void FindFeatures(int width, int height, byte yuv[], int[] rgba);
|
||||||
|
|
||||||
static {
|
|
||||||
System.loadLibrary("native_sample");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package org.opencv.samples.tutorial4;
|
package org.opencv.samples.tutorial4;
|
||||||
|
|
||||||
|
import org.opencv.android.BaseLoaderCallback;
|
||||||
|
import org.opencv.android.LoaderCallbackInterface;
|
||||||
|
import org.opencv.android.OpenCVLoader;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@ -18,6 +22,42 @@ public class Sample4Mixed extends Activity {
|
|||||||
private MenuItem mItemPreviewFeatures;
|
private MenuItem mItemPreviewFeatures;
|
||||||
private Sample4View mView;
|
private Sample4View 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("mixed_sample");
|
||||||
|
|
||||||
|
// Create and set View
|
||||||
|
mView = new Sample4View(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 Sample4Mixed() {
|
public Sample4Mixed() {
|
||||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||||
@ -27,6 +67,7 @@ public class Sample4Mixed extends Activity {
|
|||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
Log.i(TAG, "onPause");
|
Log.i(TAG, "onPause");
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
if (null != mView)
|
||||||
mView.releaseCamera();
|
mView.releaseCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +75,7 @@ public class Sample4Mixed extends Activity {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
Log.i(TAG, "onResume");
|
Log.i(TAG, "onResume");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if( !mView.openCamera() ) {
|
if((null != mView) && !mView.openCamera() ) {
|
||||||
AlertDialog ad = new AlertDialog.Builder(this).create();
|
AlertDialog ad = new AlertDialog.Builder(this).create();
|
||||||
ad.setCancelable(false); // This blocks the 'BACK' button
|
ad.setCancelable(false); // This blocks the 'BACK' button
|
||||||
ad.setMessage("Fatal error: can't open camera!");
|
ad.setMessage("Fatal error: can't open camera!");
|
||||||
@ -53,9 +94,15 @@ public class Sample4Mixed extends Activity {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Log.i(TAG, "onCreate");
|
Log.i(TAG, "onCreate");
|
||||||
|
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
mView = new Sample4View(this);
|
|
||||||
setContentView(mView);
|
Log.i(TAG, "Trying to load OpenCV library");
|
||||||
|
if (!OpenCVLoader.initAsync(OpenCVLoader.OPEN_CV_VERSION_2_4_0, this, mOpenCVCallBack))
|
||||||
|
{
|
||||||
|
Log.e(TAG, "Cannot connect to OpenCV Manager");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
@ -104,11 +104,6 @@ class Sample4View extends SampleViewBase {
|
|||||||
|
|
||||||
public native void FindFeatures(long matAddrGr, long matAddrRgba);
|
public native void FindFeatures(long matAddrGr, long matAddrRgba);
|
||||||
|
|
||||||
static {
|
|
||||||
System.loadLibrary("opencv_java");
|
|
||||||
System.loadLibrary("mixed_sample");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setViewMode(int viewMode) {
|
public void setViewMode(int viewMode) {
|
||||||
mViewMode = viewMode;
|
mViewMode = viewMode;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user