diff --git a/modules/java/android/.classpath b/modules/java/android/.classpath
index 6e9239ff0d..8d62247791 100644
--- a/modules/java/android/.classpath
+++ b/modules/java/android/.classpath
@@ -3,5 +3,5 @@
-
+
diff --git a/modules/java/android/.project b/modules/java/android/.project
index 37ed81aa51..61ce0dfa31 100644
--- a/modules/java/android/.project
+++ b/modules/java/android/.project
@@ -1,6 +1,6 @@
- OpenCV
+ opencv2.3.1
diff --git a/modules/java/android/AndroidManifest.xml b/modules/java/android/AndroidManifest.xml
index e0e8f36f55..8e50bf1589 100644
--- a/modules/java/android/AndroidManifest.xml
+++ b/modules/java/android/AndroidManifest.xml
@@ -3,9 +3,9 @@
package="org.opencv"
android:versionCode="1"
android:versionName="1.0">
-
-
+
+
diff --git a/samples/android/1-java/.project b/samples/android/1-java/.project
index 365825ad52..45ba1a67c4 100644
--- a/samples/android/1-java/.project
+++ b/samples/android/1-java/.project
@@ -32,9 +32,9 @@
- OpenCVJavaAPI_src
+ opencv2.3.1_src
2
- _android_OpenCVJavaAPI_583dbd7b/src
+ _android_opencv2_3_1_d2471b5d/src
diff --git a/samples/android/1-java/src/org/opencv/samples/s1/Sample1View.java b/samples/android/1-java/src/org/opencv/samples/s1/Sample1View.java
index 6656af29b2..f04a26fe37 100644
--- a/samples/android/1-java/src/org/opencv/samples/s1/Sample1View.java
+++ b/samples/android/1-java/src/org/opencv/samples/s1/Sample1View.java
@@ -2,12 +2,8 @@ package org.opencv.samples.s1;
import android.content.Context;
import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.hardware.Camera;
-import android.hardware.Camera.PreviewCallback;
import android.util.Log;
import android.view.SurfaceHolder;
-import android.view.SurfaceView;
import org.opencv.CvType;
import org.opencv.Mat;
@@ -18,51 +14,23 @@ import org.opencv.core;
import org.opencv.imgproc;
import org.opencv.android;
-import java.util.List;
-class Sample1View extends SurfaceView implements SurfaceHolder.Callback, Runnable {
- private static final String TAG = "Sample1Java::View";
-
- private Camera mCamera;
- private SurfaceHolder mHolder;
- private int mFrameWidth;
- private int mFrameHeight;
- private byte[] mFrame;
- private boolean mThreadRun;
-
- private Mat mYuv;
- private Mat mRgba;
- private Mat mGraySubmat;
- private Mat mIntermediateMat;
+class Sample1View extends SampleViewBase implements SurfaceHolder.Callback {
+ Mat mYuv;
+ Mat mRgba;
+ Mat mGraySubmat;
+ Mat mIntermediateMat;
public Sample1View(Context context) {
super(context);
- mHolder = getHolder();
- mHolder.addCallback(this);
}
-
+
+ @Override
public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
- if ( mCamera != null) {
- Camera.Parameters params = mCamera.getParameters();
- List sizes = params.getSupportedPreviewSizes();
- mFrameWidth = width;
- mFrameHeight = height;
-
- //selecting optimal camera preview size
- {
- double minDiff = Double.MAX_VALUE;
- for (Camera.Size size : sizes) {
- if (Math.abs(size.height - height) < minDiff) {
- mFrameWidth = size.width;
- mFrameHeight = size.height;
- minDiff = Math.abs(size.height - height);
- }
- }
- }
- params.setPreviewSize(mFrameWidth, mFrameHeight);
- mCamera.setParameters(params);
- mCamera.startPreview();
-
+ super.surfaceChanged(_holder, format, width, height);
+ Log.e("SAMP1", "surfaceChanged begin");
+ synchronized (this) {
+ Log.e("SAMP1", "surfaceChanged sync");
// initialize all required Mats before usage to minimize number of auxiliary jni calls
if(mYuv != null) mYuv.dispose();
mYuv = new Mat(mFrameHeight+mFrameHeight/2, mFrameWidth, CvType.CV_8UC1);
@@ -75,36 +43,57 @@ class Sample1View extends SurfaceView implements SurfaceHolder.Callback, Runnabl
if(mIntermediateMat != null) mIntermediateMat.dispose();
mIntermediateMat = new Mat(mFrameHeight, mFrameWidth, CvType.CV_8UC1);
- }
- }
-
- public void surfaceCreated(SurfaceHolder holder) {
- mCamera = Camera.open();
- mCamera.setPreviewCallback(
- new PreviewCallback() {
- public void onPreviewFrame(byte[] data, Camera camera) {
- synchronized(Sample1View.this) {
- mFrame = data;
- Sample1View.this.notify();
- }
- }
- }
- );
- (new Thread(this)).start();
+ }
+ Log.e("SAMP1", "surfaceChanged end");
}
- public void surfaceDestroyed(SurfaceHolder holder) {
- mThreadRun = false;
- if(mCamera != null) {
- synchronized(Sample1View.this) {
- mCamera.stopPreview();
- mCamera.setPreviewCallback(null);
- mCamera.release();
- mCamera = null;
- }
+ @Override
+ protected Bitmap processFrame(byte[] data)
+ {
+ Log.e("SAMP1", "processFrame begin");
+
+ mYuv.put(0, 0, data);
+
+ Sample1Java a = (Sample1Java)getContext();
+
+ switch(a.viewMode)
+ {
+ case Sample1Java.VIEW_MODE_GRAY:
+ imgproc.cvtColor(mGraySubmat, mRgba, imgproc.CV_GRAY2RGBA, 4);
+ break;
+ case Sample1Java.VIEW_MODE_RGBA:
+ imgproc.cvtColor(mYuv, mRgba, imgproc.CV_YUV420i2RGB, 4);
+ core.putText(mRgba, "OpenCV + Android", new Point(10,100), 3/*CV_FONT_HERSHEY_COMPLEX*/, 2, new Scalar(255, 0, 0, 255), 3);
+ break;
+ case Sample1Java.VIEW_MODE_CANNY:
+ imgproc.Canny(mGraySubmat, mIntermediateMat, 80, 100);
+ imgproc.cvtColor(mIntermediateMat, mRgba, imgproc.CV_GRAY2BGRA, 4);
+ break;
+ case Sample1Java.VIEW_MODE_SOBEL:
+ imgproc.Sobel(mGraySubmat, mIntermediateMat, CvType.CV_8U, 1, 1);
+ core.convertScaleAbs(mIntermediateMat, mIntermediateMat, 8);
+ imgproc.cvtColor(mIntermediateMat, mRgba, imgproc.CV_GRAY2BGRA, 4);
+ break;
+ case Sample1Java.VIEW_MODE_BLUR:
+ imgproc.cvtColor(mYuv, mRgba, imgproc.CV_YUV420i2RGB, 4);
+ imgproc.blur(mRgba, mRgba, new Size(15, 15));
+ break;
}
- // Explicitly dispose Mats
+ Bitmap bmp = Bitmap.createBitmap(mFrameWidth, mFrameHeight, Bitmap.Config.ARGB_8888);
+ android.MatToBitmap(mRgba, bmp);
+
+ Log.e("SAMP1", "processFrame end");
+ return bmp;
+ }
+
+ @Override
+ public void run() {
+ Log.e("SAMP1", "run");
+ super.run();
+ Log.e("SAMP1", "run2");
+
+ // Explicitly release Mats
if(mYuv != null) {
mYuv.dispose();
mYuv = null;
@@ -122,52 +111,4 @@ class Sample1View extends SurfaceView implements SurfaceHolder.Callback, Runnabl
mIntermediateMat = null;
}
}
-
- public void run() {
- mThreadRun = true;
- Log.i(TAG, "Starting thread");
- while(mThreadRun) {
- synchronized(this) {
- try {
- this.wait();
- mYuv.put(0, 0, mFrame);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- Sample1Java a = (Sample1Java)getContext();
-
- switch(a.viewMode)
- {
- case Sample1Java.VIEW_MODE_GRAY:
- imgproc.cvtColor(mGraySubmat, mRgba, imgproc.CV_GRAY2RGBA, 4);
- break;
- case Sample1Java.VIEW_MODE_RGBA:
- imgproc.cvtColor(mYuv, mRgba, imgproc.CV_YUV420i2RGB, 4);
- core.putText(mRgba, "OpenCV + Android", new Point(10,100), 3/*CV_FONT_HERSHEY_COMPLEX*/, 2, new Scalar(255, 0, 0, 255), 3);
- break;
- case Sample1Java.VIEW_MODE_CANNY:
- imgproc.Canny(mGraySubmat, mIntermediateMat, 80, 100);
- imgproc.cvtColor(mIntermediateMat, mRgba, imgproc.CV_GRAY2BGRA, 4);
- break;
- case Sample1Java.VIEW_MODE_SOBEL:
- imgproc.Sobel(mGraySubmat, mIntermediateMat, CvType.CV_8U, 1, 1);
- core.convertScaleAbs(mIntermediateMat, mIntermediateMat, 8);
- imgproc.cvtColor(mIntermediateMat, mRgba, imgproc.CV_GRAY2BGRA, 4);
- break;
- case Sample1Java.VIEW_MODE_BLUR:
- imgproc.cvtColor(mYuv, mRgba, imgproc.CV_YUV420i2RGB, 4);
- imgproc.blur(mRgba, mRgba, new Size(15, 15));
- break;
- }
-
- Bitmap bmp = Bitmap.createBitmap(mFrameWidth, mFrameHeight, Bitmap.Config.ARGB_8888);
- android.MatToBitmap(mRgba, bmp);
-
- Canvas canvas = mHolder.lockCanvas();
- canvas.drawBitmap(bmp, (canvas.getWidth()-mFrameWidth)/2, (canvas.getHeight()-mFrameHeight)/2, null);
- mHolder.unlockCanvasAndPost(canvas);
- }
- }
}
\ No newline at end of file
diff --git a/samples/android/1-java/src/org/opencv/samples/s1/SampleViewBase.java b/samples/android/1-java/src/org/opencv/samples/s1/SampleViewBase.java
new file mode 100644
index 0000000000..56ba970058
--- /dev/null
+++ b/samples/android/1-java/src/org/opencv/samples/s1/SampleViewBase.java
@@ -0,0 +1,108 @@
+package org.opencv.samples.s1;
+
+import java.util.List;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.hardware.Camera;
+import android.hardware.Camera.PreviewCallback;
+import android.util.Log;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+
+public abstract class SampleViewBase extends SurfaceView implements SurfaceHolder.Callback, Runnable {
+
+ private static final String TAG = "Sample::ViewBase";
+ private Camera mCamera;
+ private SurfaceHolder mHolder;
+ protected int mFrameWidth;
+ protected int mFrameHeight;
+ private byte[] mFrame;
+ private boolean mThreadRun;
+
+ public SampleViewBase(Context context) {
+ super(context);
+ mHolder = getHolder();
+ mHolder.addCallback(this);
+ }
+
+ public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
+ if ( mCamera != null) {
+ Camera.Parameters params = mCamera.getParameters();
+ List sizes = params.getSupportedPreviewSizes();
+ mFrameWidth = width;
+ mFrameHeight = height;
+
+ //selecting optimal camera preview size
+ {
+ double minDiff = Double.MAX_VALUE;
+ for (Camera.Size size : sizes) {
+ if (Math.abs(size.height - height) < minDiff) {
+ mFrameWidth = size.width;
+ mFrameHeight = size.height;
+ minDiff = Math.abs(size.height - height);
+ }
+ }
+ }
+ params.setPreviewSize(mFrameWidth, mFrameHeight);
+ mCamera.setParameters(params);
+ mCamera.startPreview();
+ }
+ }
+
+ public void surfaceCreated(SurfaceHolder holder) {
+ mCamera = Camera.open();
+ mCamera.setPreviewCallback(
+ new PreviewCallback() {
+ public void onPreviewFrame(byte[] data, Camera camera) {
+ synchronized(SampleViewBase.this) {
+ mFrame = data;
+ Log.i("SAMP1", "before notify");
+ SampleViewBase.this.notify();
+ Log.i("SAMP1", "after notify");
+ }
+ }
+ }
+ );
+ (new Thread(this)).start();
+ }
+
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ mThreadRun = false;
+ if(mCamera != null) {
+ synchronized(this) {
+ mCamera.stopPreview();
+ mCamera.setPreviewCallback(null);
+ mCamera.release();
+ mCamera = null;
+ }
+ }
+ }
+
+ protected abstract Bitmap processFrame(byte[] data);
+
+ public void run() {
+ mThreadRun = true;
+ Log.i(TAG, "Starting thread");
+ Bitmap bmp = null;
+ while(mThreadRun) {
+ Log.i("SAMP1", "before synchronized");
+ synchronized(this) {
+ Log.i("SAMP1", "in synchronized");
+ try {
+ this.wait();
+ Log.i("SAMP1", "before processFrame");
+ bmp = processFrame(mFrame);
+ Log.i("SAMP1", "after processFrame");
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ Canvas canvas = mHolder.lockCanvas();
+ canvas.drawBitmap(bmp, (canvas.getWidth()-mFrameWidth)/2, (canvas.getHeight()-mFrameHeight)/2, null);
+ mHolder.unlockCanvasAndPost(canvas);
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/android/4-mixed/.project b/samples/android/4-mixed/.project
index fa9b217708..62a02e4762 100644
--- a/samples/android/4-mixed/.project
+++ b/samples/android/4-mixed/.project
@@ -32,9 +32,9 @@
- OpenCVJavaAPI_src
+ opencv2.3.1_src
2
- _android_OpenCVJavaAPI_583dbd7b/src
+ _android_opencv2_3_1_d2471b5d/src