diff --git a/modules/java/android_test/.classpath b/modules/java/android_test/.classpath
index acecb835a9..90f44c9239 100644
--- a/modules/java/android_test/.classpath
+++ b/modules/java/android_test/.classpath
@@ -1,9 +1,10 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/modules/java/src/cpp/utils.cpp b/modules/java/src/cpp/utils.cpp
index d06ef74919..f137e8e79d 100644
--- a/modules/java/src/cpp/utils.cpp
+++ b/modules/java/src/cpp/utils.cpp
@@ -1,76 +1,138 @@
#include
#include "opencv2/core/core.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
#include
-#ifdef __cplusplus
+#include
+#define LOG_TAG "org.opencv.android.Utils"
+#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
+#ifdef DEBUG
+#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
+#else //!DEBUG
+#define LOGD(...)
+#endif //DEBUG
+
+using namespace cv;
+
+
extern "C" {
-#endif
/*
* Class: org_opencv_android_Utils
- * Method: nBitmapToMat(Bitmap b)
- * Signature: (L)J
+ * Method: void nBitmapToMat(Bitmap b, long m_addr)
*/
-JNIEXPORT jlong JNICALL Java_org_opencv_android_Utils_nBitmapToMat
- (JNIEnv * env, jclass cls, jobject bitmap)
+JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nBitmapToMat
+ (JNIEnv * env, jclass cls, jobject bitmap, jlong m_addr)
{
AndroidBitmapInfo info;
- void* pixels;
- cv::Mat* m = new cv::Mat();
-
- if ( AndroidBitmap_getInfo(env, bitmap, &info) < 0 )
- return (jlong)m; // can't get info
-
- if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888)
- return (jlong)m; // incompatible format
-
- if ( AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0 )
- return (jlong)m; // can't get pixels
-
- m->create(info.height, info.width, CV_8UC4);
- if(m->data && pixels)
- memcpy(m->data, pixels, info.height * info.width * 4);
-
- AndroidBitmap_unlockPixels(env, bitmap);
-
- return (jlong)m;
+ void* pixels = 0;
+ Mat& dst = *((Mat*)m_addr);
+
+ try {
+ LOGD("nBitmapToMat");
+ CV_Assert( AndroidBitmap_getInfo(env, bitmap, &info) >= 0 );
+ CV_Assert( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 ||
+ info.format == ANDROID_BITMAP_FORMAT_RGB_565 );
+ CV_Assert( AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 );
+ CV_Assert( pixels );
+ dst.create(info.height, info.width, CV_8UC4);
+ if( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 )
+ {
+ LOGD("nBitmapToMat: RGBA_8888 -> CV_8UC4");
+ Mat tmp(info.height, info.width, CV_8UC4, pixels);
+ tmp.copyTo(dst);
+ } else {
+ // info.format == ANDROID_BITMAP_FORMAT_RGB_565
+ LOGD("nBitmapToMat: RGB_565 -> CV_8UC4");
+ Mat tmp(info.height, info.width, CV_8UC2, pixels);
+ cvtColor(tmp, dst, CV_BGR5652RGBA);
+ }
+ AndroidBitmap_unlockPixels(env, bitmap);
+ return;
+ } catch(cv::Exception e) {
+ AndroidBitmap_unlockPixels(env, bitmap);
+ LOGE("nBitmapToMat catched cv::Exception: %s", e.what());
+ jclass je = env->FindClass("org/opencv/core/CvException");
+ if(!je) je = env->FindClass("java/lang/Exception");
+ env->ThrowNew(je, e.what());
+ return;
+ } catch (...) {
+ AndroidBitmap_unlockPixels(env, bitmap);
+ LOGE("nBitmapToMat catched unknown exception (...)");
+ jclass je = env->FindClass("java/lang/Exception");
+ env->ThrowNew(je, "Unknown exception in JNI code {nBitmapToMat}");
+ return;
+ }
}
/*
* Class: org_opencv_android_Utils
- * Method: nBitmapToMat(long m, Bitmap b)
- * Signature: (JL)Z
+ * Method: void nMatToBitmap(long m_addr, Bitmap b)
*/
-JNIEXPORT jboolean JNICALL Java_org_opencv_android_Utils_nMatToBitmap
- (JNIEnv * env, jclass cls, jlong m, jobject bitmap)
+JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nMatToBitmap
+ (JNIEnv * env, jclass cls, jlong m_addr, jobject bitmap)
{
AndroidBitmapInfo info;
- void* pixels;
- cv::Mat* mat = (cv::Mat*) m;
-
- if ( mat == 0 || mat->data == 0)
- return false; // no native Mat behind
-
- if ( AndroidBitmap_getInfo(env, bitmap, &info) < 0 )
- return false; // can't get info
-
- if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888)
- return false; // incompatible format
-
- if ( AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0 )
- return false; // can't get pixels
-
- if(mat->data && pixels)
- memcpy(pixels, mat->data, info.height * info.width * 4);
-
- AndroidBitmap_unlockPixels(env, bitmap);
-
- return true;
+ void* pixels = 0;
+ Mat& dst = *((Mat*)m_addr);
+
+ try {
+ LOGD("nMatToBitmap");
+ CV_Assert( AndroidBitmap_getInfo(env, bitmap, &info) >= 0 );
+ CV_Assert( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 ||
+ info.format == ANDROID_BITMAP_FORMAT_RGB_565 );
+ CV_Assert( dst.dims == 2 && info.height == (uint32_t)dst.rows && info.width == (uint32_t)dst.cols );
+ CV_Assert( dst.type() == CV_8UC1 || dst.type() == CV_8UC3 || dst.type() == CV_8UC4 );
+ CV_Assert( AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 );
+ CV_Assert( pixels );
+ if( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 )
+ {
+ Mat tmp(info.height, info.width, CV_8UC4, pixels);
+ if(dst.type() == CV_8UC1)
+ {
+ LOGD("nMatToBitmap: CV_8UC1 -> RGBA_8888");
+ cvtColor(dst, tmp, CV_GRAY2RGBA);
+ } else if(dst.type() == CV_8UC3){
+ LOGD("nMatToBitmap: CV_8UC3 -> RGBA_8888");
+ cvtColor(dst, tmp, CV_RGB2RGBA);
+ } else if(dst.type() == CV_8UC4){
+ LOGD("nMatToBitmap: CV_8UC4 -> RGBA_8888");
+ dst.copyTo(tmp);
+ }
+ } else {
+ // info.format == ANDROID_BITMAP_FORMAT_RGB_565
+ Mat tmp(info.height, info.width, CV_8UC2, pixels);
+ if(dst.type() == CV_8UC1)
+ {
+ LOGD("nMatToBitmap: CV_8UC1 -> RGB_565");
+ cvtColor(dst, tmp, CV_GRAY2BGR565);
+ } else if(dst.type() == CV_8UC3){
+ LOGD("nMatToBitmap: CV_8UC3 -> RGB_565");
+ cvtColor(dst, tmp, CV_RGB2BGR565);
+ } else if(dst.type() == CV_8UC4){
+ LOGD("nMatToBitmap: CV_8UC4 -> RGB_565");
+ cvtColor(dst, tmp, CV_RGBA2BGR565);
+ }
+ }
+ AndroidBitmap_unlockPixels(env, bitmap);
+ return;
+ } catch(cv::Exception e) {
+ AndroidBitmap_unlockPixels(env, bitmap);
+ LOGE("nMatToBitmap catched cv::Exception: %s", e.what());
+ jclass je = env->FindClass("org/opencv/core/CvException");
+ if(!je) je = env->FindClass("java/lang/Exception");
+ env->ThrowNew(je, e.what());
+ return;
+ } catch (...) {
+ AndroidBitmap_unlockPixels(env, bitmap);
+ LOGE("nMatToBitmap catched unknown exception (...)");
+ jclass je = env->FindClass("java/lang/Exception");
+ env->ThrowNew(je, "Unknown exception in JNI code {nMatToBitmap}");
+ return;
+ }
}
-#ifdef __cplusplus
-}
-#endif
+} // extern "C"
diff --git a/modules/java/src/java/android+Utils.java b/modules/java/src/java/android+Utils.java
index 6ffa2238df..55306320f6 100644
--- a/modules/java/src/java/android+Utils.java
+++ b/modules/java/src/java/android+Utils.java
@@ -73,12 +73,20 @@ public class Utils {
return decoded;
}
- public static Mat bitmapToMat(Bitmap b) {
- return new Mat(nBitmapToMat(b));
+ public static void bitmapToMat(Bitmap b, Mat m) {
+ if (b == null)
+ throw new java.lang.IllegalArgumentException("Bitmap b == null");
+ if (m == null)
+ throw new java.lang.IllegalArgumentException("Mat m == null");
+ nBitmapToMat(b, m.nativeObj);
}
- public static boolean matToBitmap(Mat m, Bitmap b) {
- return nMatToBitmap(m.nativeObj, b);
+ public static void matToBitmap(Mat m, Bitmap b) {
+ if (m == null)
+ throw new java.lang.IllegalArgumentException("Mat m == null");
+ if (b == null)
+ throw new java.lang.IllegalArgumentException("Bitmap b == null");
+ nMatToBitmap(m.nativeObj, b);
}
// native stuff
@@ -86,7 +94,7 @@ public class Utils {
System.loadLibrary("opencv_java");
}
- private static native long nBitmapToMat(Bitmap b);
+ private static native void nBitmapToMat(Bitmap b, long m_addr);
- private static native boolean nMatToBitmap(long m, Bitmap b);
+ private static native void nMatToBitmap(long m_addr, Bitmap b);
}
diff --git a/samples/android/15-puzzle/.classpath b/samples/android/15-puzzle/.classpath
index 87ce3fa5d8..a4f1e40546 100644
--- a/samples/android/15-puzzle/.classpath
+++ b/samples/android/15-puzzle/.classpath
@@ -3,6 +3,6 @@
-
-
+
+
diff --git a/samples/android/15-puzzle/.project b/samples/android/15-puzzle/.project
index 9005e16179..e0b9349d2f 100644
--- a/samples/android/15-puzzle/.project
+++ b/samples/android/15-puzzle/.project
@@ -30,11 +30,4 @@
com.android.ide.eclipse.adt.AndroidNature
org.eclipse.jdt.core.javanature
-
-
- OpenCV-2.3.1_src
- 2
- _android_OpenCV_2_3_1_df28900a/src
-
-
diff --git a/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/puzzle15View.java b/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/puzzle15View.java
index a4d18ae71f..73c9985799 100644
--- a/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/puzzle15View.java
+++ b/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/puzzle15View.java
@@ -11,6 +11,7 @@ import org.opencv.highgui.VideoCapture;
import android.content.Context;
import android.graphics.Bitmap;
+import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.View;
@@ -135,13 +136,15 @@ public class puzzle15View extends SampleCvViewBase implements OnTouchListener {
}
drawGrid(cols, rows);
-
Bitmap bmp = Bitmap.createBitmap(cols, rows, Bitmap.Config.ARGB_8888);
- if (Utils.matToBitmap(mRgba15, bmp))
+ try {
+ Utils.matToBitmap(mRgba15, bmp);
return bmp;
-
- bmp.recycle();
- return null;
+ } catch(Exception e) {
+ Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
+ bmp.recycle();
+ return null;
+ }
}
private void drawGrid(int cols, int rows) {
diff --git a/samples/android/face-detection/.classpath b/samples/android/face-detection/.classpath
index a0a90f9b1c..a4f1e40546 100644
--- a/samples/android/face-detection/.classpath
+++ b/samples/android/face-detection/.classpath
@@ -1,8 +1,8 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/samples/android/face-detection/.project b/samples/android/face-detection/.project
index 6ed0ae95ef..c8323eb085 100644
--- a/samples/android/face-detection/.project
+++ b/samples/android/face-detection/.project
@@ -1,40 +1,33 @@
-
-
- Sample - face-detection
-
-
-
-
-
- com.android.ide.eclipse.adt.ResourceManagerBuilder
-
-
-
-
- com.android.ide.eclipse.adt.PreCompilerBuilder
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- com.android.ide.eclipse.adt.ApkBuilder
-
-
-
-
-
- com.android.ide.eclipse.adt.AndroidNature
- org.eclipse.jdt.core.javanature
-
-
-
- OpenCV-2.3.1_src
- 2
- _android_OpenCV_2_3_1_df28900a/src
-
-
-
+
+
+ Sample - face-detection
+
+
+
+
+
+ com.android.ide.eclipse.adt.ResourceManagerBuilder
+
+
+
+
+ com.android.ide.eclipse.adt.PreCompilerBuilder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ com.android.ide.eclipse.adt.ApkBuilder
+
+
+
+
+
+ com.android.ide.eclipse.adt.AndroidNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/samples/android/face-detection/project.properties b/samples/android/face-detection/project.properties
index 74bb01ac06..fb3ea1f7b3 100644
--- a/samples/android/face-detection/project.properties
+++ b/samples/android/face-detection/project.properties
@@ -1,3 +1,3 @@
-android.library.reference.1=../../OpenCV-2.3.1
+android.library.reference.1=../../../android/build
# Project target.
target=android-8
diff --git a/samples/android/face-detection/src/org/opencv/samples/fd/FdView.java b/samples/android/face-detection/src/org/opencv/samples/fd/FdView.java
index 538bbdb847..cff1af33ce 100644
--- a/samples/android/face-detection/src/org/opencv/samples/fd/FdView.java
+++ b/samples/android/face-detection/src/org/opencv/samples/fd/FdView.java
@@ -89,13 +89,16 @@ class FdView extends SampleCvViewBase {
Core.rectangle(mRgba, r.tl(), r.br(), new Scalar(0, 255, 0, 255), 3);
}
- Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
+ Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.RGB_565/*.ARGB_8888*/);
- if (Utils.matToBitmap(mRgba, bmp))
+ try {
+ Utils.matToBitmap(mRgba, bmp);
return bmp;
-
- bmp.recycle();
- return null;
+ } catch(Exception e) {
+ Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
+ bmp.recycle();
+ return null;
+ }
}
@Override
diff --git a/samples/android/image-manipulations/.classpath b/samples/android/image-manipulations/.classpath
index a0a90f9b1c..a4f1e40546 100644
--- a/samples/android/image-manipulations/.classpath
+++ b/samples/android/image-manipulations/.classpath
@@ -1,8 +1,8 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/samples/android/image-manipulations/.project b/samples/android/image-manipulations/.project
index 2920cef591..dac708eec3 100644
--- a/samples/android/image-manipulations/.project
+++ b/samples/android/image-manipulations/.project
@@ -1,40 +1,33 @@
-
-
- Sample - image-manipulations
-
-
-
-
-
- com.android.ide.eclipse.adt.ResourceManagerBuilder
-
-
-
-
- com.android.ide.eclipse.adt.PreCompilerBuilder
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- com.android.ide.eclipse.adt.ApkBuilder
-
-
-
-
-
- com.android.ide.eclipse.adt.AndroidNature
- org.eclipse.jdt.core.javanature
-
-
-
- OpenCV-2.3.1_src
- 2
- _android_OpenCV_2_3_1_df28900a/src
-
-
-
+
+
+ Sample - image-manipulations
+
+
+
+
+
+ com.android.ide.eclipse.adt.ResourceManagerBuilder
+
+
+
+
+ com.android.ide.eclipse.adt.PreCompilerBuilder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ com.android.ide.eclipse.adt.ApkBuilder
+
+
+
+
+
+ com.android.ide.eclipse.adt.AndroidNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsView.java b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsView.java
index d4f74cf8fa..715dd4cb5b 100644
--- a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsView.java
+++ b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsView.java
@@ -13,6 +13,7 @@ import org.opencv.highgui.VideoCapture;
import android.content.Context;
import android.graphics.Bitmap;
+import android.util.Log;
import android.view.SurfaceHolder;
class ImageManipulationsView extends SampleCvViewBase {
@@ -135,11 +136,14 @@ class ImageManipulationsView extends SampleCvViewBase {
Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
- if (Utils.matToBitmap(mRgba, bmp))
+ try {
+ Utils.matToBitmap(mRgba, bmp);
return bmp;
-
- bmp.recycle();
- return null;
+ } catch(Exception e) {
+ Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
+ bmp.recycle();
+ return null;
+ }
}
@Override
diff --git a/samples/android/tutorial-0-androidcamera/.classpath b/samples/android/tutorial-0-androidcamera/.classpath
index 6e9239ff0d..aff8e75b8a 100644
--- a/samples/android/tutorial-0-androidcamera/.classpath
+++ b/samples/android/tutorial-0-androidcamera/.classpath
@@ -3,5 +3,5 @@
-
+
diff --git a/samples/android/tutorial-1-addopencv/.classpath b/samples/android/tutorial-1-addopencv/.classpath
index a0a90f9b1c..a4f1e40546 100644
--- a/samples/android/tutorial-1-addopencv/.classpath
+++ b/samples/android/tutorial-1-addopencv/.classpath
@@ -1,8 +1,8 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/samples/android/tutorial-1-addopencv/.project b/samples/android/tutorial-1-addopencv/.project
index 90ff95b55b..b67b0d94e7 100644
--- a/samples/android/tutorial-1-addopencv/.project
+++ b/samples/android/tutorial-1-addopencv/.project
@@ -1,40 +1,33 @@
-
-
- Tutorial 1 Basic - 1. Add OpenCV
-
-
-
-
-
- com.android.ide.eclipse.adt.ResourceManagerBuilder
-
-
-
-
- com.android.ide.eclipse.adt.PreCompilerBuilder
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- com.android.ide.eclipse.adt.ApkBuilder
-
-
-
-
-
- com.android.ide.eclipse.adt.AndroidNature
- org.eclipse.jdt.core.javanature
-
-
-
- OpenCV-2.3.1_src
- 2
- _android_OpenCV_2_3_1_df28900a/src
-
-
-
+
+
+ Tutorial 1 Basic - 1. Add OpenCV
+
+
+
+
+
+ com.android.ide.eclipse.adt.ResourceManagerBuilder
+
+
+
+
+ com.android.ide.eclipse.adt.PreCompilerBuilder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ com.android.ide.eclipse.adt.ApkBuilder
+
+
+
+
+
+ com.android.ide.eclipse.adt.AndroidNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1View.java b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1View.java
index 32aa634699..f7da21168d 100644
--- a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1View.java
+++ b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1View.java
@@ -10,6 +10,7 @@ import org.opencv.imgproc.Imgproc;
import android.content.Context;
import android.graphics.Bitmap;
+import android.util.Log;
import android.view.SurfaceHolder;
class Sample1View extends SampleViewBase {
@@ -56,11 +57,14 @@ class Sample1View extends SampleViewBase {
Bitmap bmp = Bitmap.createBitmap(getFrameWidth(), getFrameHeight(), Bitmap.Config.ARGB_8888);
- if (Utils.matToBitmap(mRgba, bmp))
+ try {
+ Utils.matToBitmap(mRgba, bmp);
return bmp;
-
- bmp.recycle();
- return null;
+ } catch(Exception e) {
+ Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
+ bmp.recycle();
+ return null;
+ }
}
@Override
diff --git a/samples/android/tutorial-2-opencvcamera/.classpath b/samples/android/tutorial-2-opencvcamera/.classpath
index a0a90f9b1c..a4f1e40546 100644
--- a/samples/android/tutorial-2-opencvcamera/.classpath
+++ b/samples/android/tutorial-2-opencvcamera/.classpath
@@ -1,8 +1,8 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/samples/android/tutorial-2-opencvcamera/.project b/samples/android/tutorial-2-opencvcamera/.project
index 5f1ca2cf5f..aa5deb422a 100644
--- a/samples/android/tutorial-2-opencvcamera/.project
+++ b/samples/android/tutorial-2-opencvcamera/.project
@@ -1,40 +1,33 @@
-
-
- Tutorial 1 Basic - 2. Use OpenCV Camera
-
-
-
-
-
- com.android.ide.eclipse.adt.ResourceManagerBuilder
-
-
-
-
- com.android.ide.eclipse.adt.PreCompilerBuilder
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- com.android.ide.eclipse.adt.ApkBuilder
-
-
-
-
-
- com.android.ide.eclipse.adt.AndroidNature
- org.eclipse.jdt.core.javanature
-
-
-
- OpenCV-2.3.1_src
- 2
- _android_OpenCV_2_3_1_df28900a/src
-
-
-
+
+
+ Tutorial 1 Basic - 2. Use OpenCV Camera
+
+
+
+
+
+ com.android.ide.eclipse.adt.ResourceManagerBuilder
+
+
+
+
+ com.android.ide.eclipse.adt.PreCompilerBuilder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ com.android.ide.eclipse.adt.ApkBuilder
+
+
+
+
+
+ com.android.ide.eclipse.adt.AndroidNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2View.java b/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2View.java
index bbadc5ef34..406ffe2123 100644
--- a/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2View.java
+++ b/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2View.java
@@ -11,6 +11,7 @@ import org.opencv.highgui.VideoCapture;
import android.content.Context;
import android.graphics.Bitmap;
+import android.util.Log;
import android.view.SurfaceHolder;
class Sample2View extends SampleCvViewBase {
@@ -54,11 +55,14 @@ class Sample2View extends SampleCvViewBase {
Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
- if (Utils.matToBitmap(mRgba, bmp))
+ try {
+ Utils.matToBitmap(mRgba, bmp);
return bmp;
-
- bmp.recycle();
- return null;
+ } catch(Exception e) {
+ Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
+ bmp.recycle();
+ return null;
+ }
}
@Override
diff --git a/samples/android/tutorial-3-native/.classpath b/samples/android/tutorial-3-native/.classpath
index 609aa00ebc..aff8e75b8a 100644
--- a/samples/android/tutorial-3-native/.classpath
+++ b/samples/android/tutorial-3-native/.classpath
@@ -1,7 +1,7 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/samples/android/tutorial-3-native/.project b/samples/android/tutorial-3-native/.project
index 6cf7ad3f2c..61e222211f 100644
--- a/samples/android/tutorial-3-native/.project
+++ b/samples/android/tutorial-3-native/.project
@@ -1,43 +1,33 @@
-
-
- Tutorial 2 Advanced - 1. Add Native OpenCV
-
-
-
-
-
- com.android.ide.eclipse.adt.ResourceManagerBuilder
-
-
-
-
- com.android.ide.eclipse.adt.PreCompilerBuilder
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- com.android.ide.eclipse.adt.ApkBuilder
-
-
-
-
- org.eclipse.ui.externaltools.ExternalToolBuilder
- auto,full,incremental,
-
-
- LaunchConfigHandle
- <project>/.externalToolBuilders/Tutorial 2.1 Builder.launch
-
-
-
-
-
- com.android.ide.eclipse.adt.AndroidNature
- org.eclipse.jdt.core.javanature
-
-
+
+
+ Tutorial 2 Advanced - 1. Add Native OpenCV
+
+
+
+
+
+ com.android.ide.eclipse.adt.ResourceManagerBuilder
+
+
+
+
+ com.android.ide.eclipse.adt.PreCompilerBuilder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ com.android.ide.eclipse.adt.ApkBuilder
+
+
+
+
+
+ com.android.ide.eclipse.adt.AndroidNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/samples/android/tutorial-4-mixed/.classpath b/samples/android/tutorial-4-mixed/.classpath
index a0a90f9b1c..a4f1e40546 100644
--- a/samples/android/tutorial-4-mixed/.classpath
+++ b/samples/android/tutorial-4-mixed/.classpath
@@ -1,8 +1,8 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/samples/android/tutorial-4-mixed/.project b/samples/android/tutorial-4-mixed/.project
index d5f3427685..05a338e9df 100644
--- a/samples/android/tutorial-4-mixed/.project
+++ b/samples/android/tutorial-4-mixed/.project
@@ -1,40 +1,33 @@
-
-
- Tutorial 2 Advanced - 2. Mix Java+Native OpenCV
-
-
-
-
-
- com.android.ide.eclipse.adt.ResourceManagerBuilder
-
-
-
-
- com.android.ide.eclipse.adt.PreCompilerBuilder
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- com.android.ide.eclipse.adt.ApkBuilder
-
-
-
-
-
- com.android.ide.eclipse.adt.AndroidNature
- org.eclipse.jdt.core.javanature
-
-
-
- OpenCV-2.3.1_src
- 2
- _android_OpenCV_2_3_1_df28900a/src
-
-
-
+
+
+ Tutorial 2 Advanced - 2. Mix Java+Native OpenCV
+
+
+
+
+
+ com.android.ide.eclipse.adt.ResourceManagerBuilder
+
+
+
+
+ com.android.ide.eclipse.adt.PreCompilerBuilder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ com.android.ide.eclipse.adt.ApkBuilder
+
+
+
+
+
+ com.android.ide.eclipse.adt.AndroidNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4View.java b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4View.java
index 94f421fd90..29f782d4c1 100644
--- a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4View.java
+++ b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4View.java
@@ -7,6 +7,7 @@ import org.opencv.imgproc.Imgproc;
import android.content.Context;
import android.graphics.Bitmap;
+import android.util.Log;
import android.view.SurfaceHolder;
class Sample4View extends SampleViewBase {
@@ -56,11 +57,14 @@ class Sample4View extends SampleViewBase {
Bitmap bmp = Bitmap.createBitmap(getFrameWidth(), getFrameHeight(), Bitmap.Config.ARGB_8888);
- if (Utils.matToBitmap(mRgba, bmp))
+ try {
+ Utils.matToBitmap(mRgba, bmp);
return bmp;
-
- bmp.recycle();
- return null;
+ } catch(Exception e) {
+ Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
+ bmp.recycle();
+ return null;
+ }
}
@Override