Commit 62591a1d authored by Andrey Pavlenko's avatar Andrey Pavlenko

#1283, Mat <->Bitmap converters are updated to support CV_8UC(1,3,4) &…

#1283, Mat <->Bitmap converters are updated to support CV_8UC(1,3,4) & non-continuous Mat-s and RGBA_8888 & RGB_565 Bitmaps; Android samples project files are updated according to the latest SDK req-s.
parent f7fd7929
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="src" path="OpenCV_src"/> <classpathentry kind="src" path="OpenCV_src"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
</classpath> <classpathentry kind="output" path="bin/classes"/>
</classpath>
#include <jni.h> #include <jni.h>
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <android/bitmap.h> #include <android/bitmap.h>
#ifdef __cplusplus #include <android/log.h>
#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" { extern "C" {
#endif
/* /*
* Class: org_opencv_android_Utils * Class: org_opencv_android_Utils
* Method: nBitmapToMat(Bitmap b) * Method: void nBitmapToMat(Bitmap b, long m_addr)
* Signature: (L)J
*/ */
JNIEXPORT jlong JNICALL Java_org_opencv_android_Utils_nBitmapToMat JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nBitmapToMat
(JNIEnv * env, jclass cls, jobject bitmap) (JNIEnv * env, jclass cls, jobject bitmap, jlong m_addr)
{ {
AndroidBitmapInfo info; AndroidBitmapInfo info;
void* pixels; void* pixels = 0;
cv::Mat* m = new cv::Mat(); Mat& dst = *((Mat*)m_addr);
if ( AndroidBitmap_getInfo(env, bitmap, &info) < 0 ) try {
return (jlong)m; // can't get info LOGD("nBitmapToMat");
CV_Assert( AndroidBitmap_getInfo(env, bitmap, &info) >= 0 );
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) CV_Assert( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 ||
return (jlong)m; // incompatible format info.format == ANDROID_BITMAP_FORMAT_RGB_565 );
CV_Assert( AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 );
if ( AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0 ) CV_Assert( pixels );
return (jlong)m; // can't get pixels dst.create(info.height, info.width, CV_8UC4);
if( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 )
m->create(info.height, info.width, CV_8UC4); {
if(m->data && pixels) LOGD("nBitmapToMat: RGBA_8888 -> CV_8UC4");
memcpy(m->data, pixels, info.height * info.width * 4); Mat tmp(info.height, info.width, CV_8UC4, pixels);
tmp.copyTo(dst);
AndroidBitmap_unlockPixels(env, bitmap); } else {
// info.format == ANDROID_BITMAP_FORMAT_RGB_565
return (jlong)m; 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 * Class: org_opencv_android_Utils
* Method: nBitmapToMat(long m, Bitmap b) * Method: void nMatToBitmap(long m_addr, Bitmap b)
* Signature: (JL)Z
*/ */
JNIEXPORT jboolean JNICALL Java_org_opencv_android_Utils_nMatToBitmap JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nMatToBitmap
(JNIEnv * env, jclass cls, jlong m, jobject bitmap) (JNIEnv * env, jclass cls, jlong m_addr, jobject bitmap)
{ {
AndroidBitmapInfo info; AndroidBitmapInfo info;
void* pixels; void* pixels = 0;
cv::Mat* mat = (cv::Mat*) m; Mat& dst = *((Mat*)m_addr);
if ( mat == 0 || mat->data == 0) try {
return false; // no native Mat behind LOGD("nMatToBitmap");
CV_Assert( AndroidBitmap_getInfo(env, bitmap, &info) >= 0 );
if ( AndroidBitmap_getInfo(env, bitmap, &info) < 0 ) CV_Assert( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 ||
return false; // can't get info info.format == ANDROID_BITMAP_FORMAT_RGB_565 );
CV_Assert( dst.dims == 2 && info.height == (uint32_t)dst.rows && info.width == (uint32_t)dst.cols );
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) CV_Assert( dst.type() == CV_8UC1 || dst.type() == CV_8UC3 || dst.type() == CV_8UC4 );
return false; // incompatible format CV_Assert( AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 );
CV_Assert( pixels );
if ( AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0 ) if( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 )
return false; // can't get pixels {
Mat tmp(info.height, info.width, CV_8UC4, pixels);
if(mat->data && pixels) if(dst.type() == CV_8UC1)
memcpy(pixels, mat->data, info.height * info.width * 4); {
LOGD("nMatToBitmap: CV_8UC1 -> RGBA_8888");
AndroidBitmap_unlockPixels(env, bitmap); cvtColor(dst, tmp, CV_GRAY2RGBA);
} else if(dst.type() == CV_8UC3){
return true; 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 } // extern "C"
}
#endif
...@@ -73,12 +73,20 @@ public class Utils { ...@@ -73,12 +73,20 @@ public class Utils {
return decoded; return decoded;
} }
public static Mat bitmapToMat(Bitmap b) { public static void bitmapToMat(Bitmap b, Mat m) {
return new Mat(nBitmapToMat(b)); 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) { public static void matToBitmap(Mat m, Bitmap b) {
return nMatToBitmap(m.nativeObj, 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 // native stuff
...@@ -86,7 +94,7 @@ public class Utils { ...@@ -86,7 +94,7 @@ public class Utils {
System.loadLibrary("opencv_java"); 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);
} }
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="OpenCV-2.3.1_src"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>
...@@ -30,11 +30,4 @@ ...@@ -30,11 +30,4 @@
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
<linkedResources>
<link>
<name>OpenCV-2.3.1_src</name>
<type>2</type>
<locationURI>_android_OpenCV_2_3_1_df28900a/src</locationURI>
</link>
</linkedResources>
</projectDescription> </projectDescription>
...@@ -11,6 +11,7 @@ import org.opencv.highgui.VideoCapture; ...@@ -11,6 +11,7 @@ import org.opencv.highgui.VideoCapture;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.View; import android.view.View;
...@@ -135,13 +136,15 @@ public class puzzle15View extends SampleCvViewBase implements OnTouchListener { ...@@ -135,13 +136,15 @@ public class puzzle15View extends SampleCvViewBase implements OnTouchListener {
} }
drawGrid(cols, rows); drawGrid(cols, rows);
Bitmap bmp = Bitmap.createBitmap(cols, rows, Bitmap.Config.ARGB_8888); Bitmap bmp = Bitmap.createBitmap(cols, rows, Bitmap.Config.ARGB_8888);
if (Utils.matToBitmap(mRgba15, bmp)) try {
Utils.matToBitmap(mRgba15, bmp);
return bmp; return bmp;
} catch(Exception e) {
bmp.recycle(); Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
return null; bmp.recycle();
return null;
}
} }
private void drawGrid(int cols, int rows) { private void drawGrid(int cols, int rows) {
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="OpenCV-2.3.1_src"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>Sample - face-detection</name> <name>Sample - face-detection</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name> <name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
<linkedResources> </projectDescription>
<link>
<name>OpenCV-2.3.1_src</name>
<type>2</type>
<locationURI>_android_OpenCV_2_3_1_df28900a/src</locationURI>
</link>
</linkedResources>
</projectDescription>
android.library.reference.1=../../OpenCV-2.3.1 android.library.reference.1=../../../android/build
# Project target. # Project target.
target=android-8 target=android-8
...@@ -89,13 +89,16 @@ class FdView extends SampleCvViewBase { ...@@ -89,13 +89,16 @@ class FdView extends SampleCvViewBase {
Core.rectangle(mRgba, r.tl(), r.br(), new Scalar(0, 255, 0, 255), 3); 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; return bmp;
} catch(Exception e) {
bmp.recycle(); Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
return null; bmp.recycle();
return null;
}
} }
@Override @Override
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="OpenCV-2.3.1_src"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>Sample - image-manipulations</name> <name>Sample - image-manipulations</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name> <name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
<linkedResources> </projectDescription>
<link>
<name>OpenCV-2.3.1_src</name>
<type>2</type>
<locationURI>_android_OpenCV_2_3_1_df28900a/src</locationURI>
</link>
</linkedResources>
</projectDescription>
...@@ -13,6 +13,7 @@ import org.opencv.highgui.VideoCapture; ...@@ -13,6 +13,7 @@ import org.opencv.highgui.VideoCapture;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
class ImageManipulationsView extends SampleCvViewBase { class ImageManipulationsView extends SampleCvViewBase {
...@@ -135,11 +136,14 @@ class ImageManipulationsView extends SampleCvViewBase { ...@@ -135,11 +136,14 @@ class ImageManipulationsView extends SampleCvViewBase {
Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888); Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
if (Utils.matToBitmap(mRgba, bmp)) try {
Utils.matToBitmap(mRgba, bmp);
return bmp; return bmp;
} catch(Exception e) {
bmp.recycle(); Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
return null; bmp.recycle();
return null;
}
} }
@Override @Override
......
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="OpenCV-2.3.1_src"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>Tutorial 1 Basic - 1. Add OpenCV</name> <name>Tutorial 1 Basic - 1. Add OpenCV</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name> <name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
<linkedResources> </projectDescription>
<link>
<name>OpenCV-2.3.1_src</name>
<type>2</type>
<locationURI>_android_OpenCV_2_3_1_df28900a/src</locationURI>
</link>
</linkedResources>
</projectDescription>
...@@ -10,6 +10,7 @@ import org.opencv.imgproc.Imgproc; ...@@ -10,6 +10,7 @@ import org.opencv.imgproc.Imgproc;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
class Sample1View extends SampleViewBase { class Sample1View extends SampleViewBase {
...@@ -56,11 +57,14 @@ class Sample1View extends SampleViewBase { ...@@ -56,11 +57,14 @@ class Sample1View extends SampleViewBase {
Bitmap bmp = Bitmap.createBitmap(getFrameWidth(), getFrameHeight(), Bitmap.Config.ARGB_8888); Bitmap bmp = Bitmap.createBitmap(getFrameWidth(), getFrameHeight(), Bitmap.Config.ARGB_8888);
if (Utils.matToBitmap(mRgba, bmp)) try {
Utils.matToBitmap(mRgba, bmp);
return bmp; return bmp;
} catch(Exception e) {
bmp.recycle(); Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
return null; bmp.recycle();
return null;
}
} }
@Override @Override
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="OpenCV-2.3.1_src"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>Tutorial 1 Basic - 2. Use OpenCV Camera</name> <name>Tutorial 1 Basic - 2. Use OpenCV Camera</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name> <name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
<linkedResources> </projectDescription>
<link>
<name>OpenCV-2.3.1_src</name>
<type>2</type>
<locationURI>_android_OpenCV_2_3_1_df28900a/src</locationURI>
</link>
</linkedResources>
</projectDescription>
...@@ -11,6 +11,7 @@ import org.opencv.highgui.VideoCapture; ...@@ -11,6 +11,7 @@ import org.opencv.highgui.VideoCapture;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
class Sample2View extends SampleCvViewBase { class Sample2View extends SampleCvViewBase {
...@@ -54,11 +55,14 @@ class Sample2View extends SampleCvViewBase { ...@@ -54,11 +55,14 @@ class Sample2View extends SampleCvViewBase {
Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888); Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
if (Utils.matToBitmap(mRgba, bmp)) try {
Utils.matToBitmap(mRgba, bmp);
return bmp; return bmp;
} catch(Exception e) {
bmp.recycle(); Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
return null; bmp.recycle();
return null;
}
} }
@Override @Override
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>Tutorial 2 Advanced - 1. Add Native OpenCV</name> <name>Tutorial 2 Advanced - 1. Add Native OpenCV</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name> <name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> </buildSpec>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name> <natures>
<triggers>auto,full,incremental,</triggers> <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<arguments> <nature>org.eclipse.jdt.core.javanature</nature>
<dictionary> </natures>
<key>LaunchConfigHandle</key> </projectDescription>
<value>&lt;project&gt;/.externalToolBuilders/Tutorial 2.1 Builder.launch</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="OpenCV-2.3.1_src"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>Tutorial 2 Advanced - 2. Mix Java+Native OpenCV</name> <name>Tutorial 2 Advanced - 2. Mix Java+Native OpenCV</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name> <name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
<linkedResources> </projectDescription>
<link>
<name>OpenCV-2.3.1_src</name>
<type>2</type>
<locationURI>_android_OpenCV_2_3_1_df28900a/src</locationURI>
</link>
</linkedResources>
</projectDescription>
...@@ -7,6 +7,7 @@ import org.opencv.imgproc.Imgproc; ...@@ -7,6 +7,7 @@ import org.opencv.imgproc.Imgproc;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
class Sample4View extends SampleViewBase { class Sample4View extends SampleViewBase {
...@@ -56,11 +57,14 @@ class Sample4View extends SampleViewBase { ...@@ -56,11 +57,14 @@ class Sample4View extends SampleViewBase {
Bitmap bmp = Bitmap.createBitmap(getFrameWidth(), getFrameHeight(), Bitmap.Config.ARGB_8888); Bitmap bmp = Bitmap.createBitmap(getFrameWidth(), getFrameHeight(), Bitmap.Config.ARGB_8888);
if (Utils.matToBitmap(mRgba, bmp)) try {
Utils.matToBitmap(mRgba, bmp);
return bmp; return bmp;
} catch(Exception e) {
bmp.recycle(); Log.e("org.opencv.samples.puzzle15", "Utils.matToBitmap() throws an exception: " + e.getMessage());
return null; bmp.recycle();
return null;
}
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment