diff --git a/android/service/doc/AndroidAppUsageModel.dia b/android/service/doc/AndroidAppUsageModel.dia index 9f7146985..0313d5c64 100644 Binary files a/android/service/doc/AndroidAppUsageModel.dia and b/android/service/doc/AndroidAppUsageModel.dia differ diff --git a/android/service/doc/build_uml.py b/android/service/doc/build_uml.py index 9909a73c4..df9eb7bcd 100755 --- a/android/service/doc/build_uml.py +++ b/android/service/doc/build_uml.py @@ -20,4 +20,4 @@ if (not os.path.exists(TARGET_PATH)): for filename in os.listdir("."): if ("dia" == filename[-3:]): - os.system("%s --export %s %s" % (DiaPath, os.path.join(TARGET_PATH, filename[0:len(filename)-4] + ".png"), filename)) \ No newline at end of file + os.system("%s --export %s %s" % (DiaPath, os.path.join(TARGET_PATH, filename[0:len(filename)-4] + ".png"), filename)) \ No newline at end of file diff --git a/android/service/doc/img/AndroidAppUsageModel.png b/android/service/doc/img/AndroidAppUsageModel.png index 81d03acaa..b5ec637c7 100644 Binary files a/android/service/doc/img/AndroidAppUsageModel.png and b/android/service/doc/img/AndroidAppUsageModel.png differ diff --git a/android/service/engine/AndroidManifest.xml b/android/service/engine/AndroidManifest.xml index f29c72f53..b1d6f691c 100644 --- a/android/service/engine/AndroidManifest.xml +++ b/android/service/engine/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="20" + android:versionName="2.0" > diff --git a/android/service/engine/jni/include/EngineCommon.h b/android/service/engine/jni/include/EngineCommon.h index 99b5af30d..67a94e270 100644 --- a/android/service/engine/jni/include/EngineCommon.h +++ b/android/service/engine/jni/include/EngineCommon.h @@ -6,7 +6,7 @@ #define LOG_TAG "OpenCVEngine" #ifndef OPEN_CV_ENGINE_VERSION - #define OPEN_CV_ENGINE_VERSION 1 + #define OPEN_CV_ENGINE_VERSION 2 #endif #define LIB_OPENCV_INFO_NAME "libopencv_info.so" diff --git a/modules/java/generator/src/java/android+AsyncServiceHelper.java b/modules/java/generator/src/java/android+AsyncServiceHelper.java index 6e86f7541..adf0e41a1 100644 --- a/modules/java/generator/src/java/android+AsyncServiceHelper.java +++ b/modules/java/generator/src/java/android+AsyncServiceHelper.java @@ -41,7 +41,7 @@ class AsyncServiceHelper } protected static final String TAG = "OpenCVManager/Helper"; - protected static final int MINIMUM_ENGINE_VERSION = 1; + protected static final int MINIMUM_ENGINE_VERSION = 2; protected OpenCVEngineInterface mEngineService; protected LoaderCallbackInterface mUserAppCallback; protected String mOpenCVersion; diff --git a/modules/java/generator/src/java/android+BaseLoaderCallback.java b/modules/java/generator/src/java/android+BaseLoaderCallback.java index edc94875b..6d6a9b8da 100644 --- a/modules/java/generator/src/java/android+BaseLoaderCallback.java +++ b/modules/java/generator/src/java/android+BaseLoaderCallback.java @@ -52,7 +52,7 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface { Log.d(TAG, "OpenCV Manager Service is uncompatible with this app!"); AlertDialog IncomatibilityMessage = new AlertDialog.Builder(mAppContext).create(); IncomatibilityMessage.setTitle("OpenCV Manager"); - IncomatibilityMessage.setMessage("OpenCV Manager service is incompatible with this app. Update it!"); + IncomatibilityMessage.setMessage("OpenCV Manager service is incompatible with this app. Try to update it via Google Play."); IncomatibilityMessage.setCancelable(false); // This blocks the 'BACK' button IncomatibilityMessage.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { @@ -60,7 +60,7 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface { } }); IncomatibilityMessage.show(); - } + } break; /** Other status, i.e. INIT_FAILED. **/ default: { @@ -113,7 +113,7 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface { { AlertDialog WaitMessage = new AlertDialog.Builder(mAppContext).create(); WaitMessage.setTitle("OpenCV is not ready"); - WaitMessage.setMessage("Installation is in progeress. Wait or exit?"); + WaitMessage.setMessage("Installation is in progress. Wait or exit?"); WaitMessage.setCancelable(false); // This blocks the 'BACK' button WaitMessage.setButton(AlertDialog.BUTTON_POSITIVE, "Wait", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { diff --git a/modules/java/generator/src/java/android+JavaCameraView.java b/modules/java/generator/src/java/android+JavaCameraView.java index 6e2b6cade..0d67c9dda 100644 --- a/modules/java/generator/src/java/android+JavaCameraView.java +++ b/modules/java/generator/src/java/android+JavaCameraView.java @@ -1,6 +1,5 @@ package org.opencv.android; -import java.io.IOException; import java.util.List; import android.annotation.TargetApi; @@ -36,7 +35,8 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb private Mat mBaseMat; private byte mBuffer[]; - + private Mat[] mFrameChain; + private int mChainIdx = 0; private Thread mThread; private boolean mStopThread; @@ -65,6 +65,7 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb @TargetApi(11) protected boolean initializeCamera(int width, int height) { Log.d(TAG, "Initialize java camera"); + boolean result = true; synchronized (this) { mCamera = null; @@ -99,59 +100,76 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb Log.d(TAG, "getSupportedPreviewSizes()"); List sizes = params.getSupportedPreviewSizes(); - /* Select the size that fits surface considering maximum size allowed */ - Size frameSize = calculateCameraFrameSize(sizes, new JavaCameraSizeAccessor(), width, height); + if (sizes != null) { + /* Select the size that fits surface considering maximum size allowed */ + Size frameSize = calculateCameraFrameSize(sizes, new JavaCameraSizeAccessor(), width, height); - params.setPreviewFormat(ImageFormat.NV21); - Log.d(TAG, "Set preview size to " + Integer.valueOf((int)frameSize.width) + "x" + Integer.valueOf((int)frameSize.height)); - params.setPreviewSize((int)frameSize.width, (int)frameSize.height); + params.setPreviewFormat(ImageFormat.NV21); + Log.d(TAG, "Set preview size to " + Integer.valueOf((int)frameSize.width) + "x" + Integer.valueOf((int)frameSize.height)); + params.setPreviewSize((int)frameSize.width, (int)frameSize.height); - List FocusModes = params.getSupportedFocusModes(); - if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) - { - params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); + List FocusModes = params.getSupportedFocusModes(); + if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) + { + params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); + } + + mCamera.setParameters(params); + params = mCamera.getParameters(); + + mFrameWidth = params.getPreviewSize().width; + mFrameHeight = params.getPreviewSize().height; + + int size = mFrameWidth * mFrameHeight; + size = size * ImageFormat.getBitsPerPixel(params.getPreviewFormat()) / 8; + mBuffer = new byte[size]; + + mCamera.addCallbackBuffer(mBuffer); + mCamera.setPreviewCallbackWithBuffer(this); + + mBaseMat = new Mat(mFrameHeight + (mFrameHeight/2), mFrameWidth, CvType.CV_8UC1); + + mFrameChain = new Mat[2]; + mFrameChain[0] = new Mat(); + mFrameChain[1] = new Mat(); + + AllocateCache(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + mSurfaceTexture = new SurfaceTexture(MAGIC_TEXTURE_ID); + getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); + mCamera.setPreviewTexture(mSurfaceTexture); + } else + mCamera.setPreviewDisplay(null); + + /* Finally we are ready to start the preview */ + Log.d(TAG, "startPreview"); + mCamera.startPreview(); } - - mCamera.setParameters(params); - params = mCamera.getParameters(); - - mFrameWidth = params.getPreviewSize().width; - mFrameHeight = params.getPreviewSize().height; - - int size = mFrameWidth * mFrameHeight; - size = size * ImageFormat.getBitsPerPixel(params.getPreviewFormat()) / 8; - mBuffer = new byte[size]; - - mCamera.addCallbackBuffer(mBuffer); - mCamera.setPreviewCallbackWithBuffer(this); - - mBaseMat = new Mat(mFrameHeight + (mFrameHeight/2), mFrameWidth, CvType.CV_8UC1); - - AllocateCache(); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - mSurfaceTexture = new SurfaceTexture(MAGIC_TEXTURE_ID); - getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); - mCamera.setPreviewTexture(mSurfaceTexture); - } else - mCamera.setPreviewDisplay(null); - } catch (IOException e) { + else + result = false; + } catch (Exception e) { + result = false; e.printStackTrace(); } - - /* Finally we are ready to start the preview */ - Log.d(TAG, "startPreview"); - mCamera.startPreview(); } - return true; + return result; } protected void releaseCamera() { synchronized (this) { - mCamera.stopPreview(); - mCamera.release(); + if (mCamera != null) { + mCamera.stopPreview(); + mCamera.release(); + } mCamera = null; + if (mBaseMat != null) + mBaseMat.release(); + if (mFrameChain != null) { + mFrameChain[0].release(); + mFrameChain[1].release(); + } } } @@ -187,7 +205,8 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb this.notify(); } Log.d(TAG, "Wating for thread"); - mThread.join(); + if (mThread != null) + mThread.join(); } catch (InterruptedException e) { e.printStackTrace(); } finally { @@ -224,19 +243,19 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb } if (!mStopThread) { - Mat frameMat = new Mat(); switch (mPreviewFormat) { case Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA: - Imgproc.cvtColor(mBaseMat, frameMat, Imgproc.COLOR_YUV2RGBA_NV21, 4); + Imgproc.cvtColor(mBaseMat, mFrameChain[mChainIdx], Imgproc.COLOR_YUV2RGBA_NV21, 4); break; case Highgui.CV_CAP_ANDROID_GREY_FRAME: - frameMat = mBaseMat.submat(0, mFrameHeight, 0, mFrameWidth); + mFrameChain[mChainIdx] = mBaseMat.submat(0, mFrameHeight, 0, mFrameWidth); break; default: Log.e(TAG, "Invalid frame format! Only RGBA and Gray Scale are supported!"); }; - deliverAndDrawFrame(frameMat); - frameMat.release(); + if (!mFrameChain[mChainIdx].empty()) + deliverAndDrawFrame(mFrameChain[mChainIdx]); + mChainIdx = 1 - mChainIdx; } } while (!mStopThread); Log.d(TAG, "Finish processing thread"); diff --git a/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/Puzzle15Activity.java b/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/Puzzle15Activity.java index c6cb1a1b2..a74b0b4d7 100644 --- a/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/Puzzle15Activity.java +++ b/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/Puzzle15Activity.java @@ -63,7 +63,8 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener, @Override public void onPause() { - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); super.onPause(); } @@ -76,7 +77,8 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener, public void onDestroy() { super.onDestroy(); - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); } @Override diff --git a/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetectionActivity.java b/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetectionActivity.java index be736b938..13ffc685d 100644 --- a/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetectionActivity.java +++ b/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetectionActivity.java @@ -78,7 +78,8 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe @Override public void onPause() { - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); super.onPause(); } @@ -91,7 +92,8 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe public void onDestroy() { super.onDestroy(); - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); } public void onCameraViewStarted(int width, int height) { @@ -100,7 +102,7 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe mSpectrum = new Mat(); mBlobColorRgba = new Scalar(255); mBlobColorHsv = new Scalar(255); - SPECTRUM_SIZE = new Size(200, 32); + SPECTRUM_SIZE = new Size(200, 64); CONTOUR_COLOR = new Scalar(255,0,0,255); } @@ -152,6 +154,9 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe mIsColorSelected = true; + touchedRegionRgba.release(); + touchedRegionHsv.release(); + return false; // don't need subsequent touch events } @@ -164,10 +169,10 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe Log.e(TAG, "Contours count: " + contours.size()); Imgproc.drawContours(mRgba, contours, -1, CONTOUR_COLOR); - Mat colorLabel = mRgba.submat(2, 34, 2, 34); + Mat colorLabel = mRgba.submat(4, 68, 4, 68); colorLabel.setTo(mBlobColorRgba); - Mat spectrumLabel = mRgba.submat(2, 2 + mSpectrum.rows(), 38, 38 + mSpectrum.cols()); + Mat spectrumLabel = mRgba.submat(4, 4 + mSpectrum.rows(), 70, 70 + mSpectrum.cols()); mSpectrum.copyTo(spectrumLabel); } diff --git a/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetector.java b/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetector.java index 08c499a58..21988a81a 100644 --- a/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetector.java +++ b/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetector.java @@ -22,6 +22,13 @@ public class ColorBlobDetector { private Mat mSpectrum = new Mat(); private List mContours = new ArrayList(); + // Cache + Mat mPyrDownMat = new Mat(); + Mat mHsvMat = new Mat(); + Mat mMask = new Mat(); + Mat mDilatedMask = new Mat(); + Mat mHierarchy = new Mat(); + public void setColorRadius(Scalar radius) { mColorRadius = radius; } @@ -61,23 +68,17 @@ public class ColorBlobDetector { } public void process(Mat rgbaImage) { - Mat pyrDownMat = new Mat(); + Imgproc.pyrDown(rgbaImage, mPyrDownMat); + Imgproc.pyrDown(mPyrDownMat, mPyrDownMat); - Imgproc.pyrDown(rgbaImage, pyrDownMat); - Imgproc.pyrDown(pyrDownMat, pyrDownMat); + Imgproc.cvtColor(mPyrDownMat, mHsvMat, Imgproc.COLOR_RGB2HSV_FULL); - Mat hsvMat = new Mat(); - Imgproc.cvtColor(pyrDownMat, hsvMat, Imgproc.COLOR_RGB2HSV_FULL); - - Mat Mask = new Mat(); - Core.inRange(hsvMat, mLowerBound, mUpperBound, Mask); - Mat dilatedMask = new Mat(); - Imgproc.dilate(Mask, dilatedMask, new Mat()); + Core.inRange(mHsvMat, mLowerBound, mUpperBound, mMask); + Imgproc.dilate(mMask, mDilatedMask, new Mat()); List contours = new ArrayList(); - Mat hierarchy = new Mat(); - Imgproc.findContours(dilatedMask, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); + Imgproc.findContours(mDilatedMask, contours, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); // Find max contour area double maxArea = 0; diff --git a/samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java b/samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java index 0bb4978a0..9470a8fd1 100644 --- a/samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java +++ b/samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java @@ -50,7 +50,7 @@ public class FdActivity extends Activity implements CvCameraViewListener { private int mDetectorType = JAVA_DETECTOR; private String[] mDetectorName; - private float mRelativeFaceSize = 0; + private float mRelativeFaceSize = 0.2f; private int mAbsoluteFaceSize = 0; private CameraBridgeViewBase mOpenCvCameraView; @@ -132,7 +132,8 @@ public class FdActivity extends Activity implements CvCameraViewListener { @Override public void onPause() { - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); super.onPause(); } diff --git a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java index 569de5dc7..26f7e8317 100644 --- a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java +++ b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java @@ -113,7 +113,8 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView @Override public void onPause() { - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); super.onPause(); } @@ -126,7 +127,8 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView public void onDestroy() { super.onDestroy(); - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); } @Override diff --git a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java index beb368f96..6478f3bb0 100644 --- a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java +++ b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java @@ -68,7 +68,8 @@ public class Sample1Java extends Activity implements CvCameraViewListener { @Override public void onPause() { - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); super.onPause(); } @@ -81,7 +82,8 @@ public class Sample1Java extends Activity implements CvCameraViewListener { public void onDestroy() { super.onDestroy(); - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); } @Override diff --git a/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2NativeCamera.java b/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2NativeCamera.java index 8fbdeef8e..dcdffe325 100644 --- a/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2NativeCamera.java +++ b/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2NativeCamera.java @@ -75,7 +75,8 @@ public class Sample2NativeCamera extends Activity implements CvCameraViewListene @Override public void onPause() { - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); super.onPause(); } @@ -88,7 +89,8 @@ public class Sample2NativeCamera extends Activity implements CvCameraViewListene public void onDestroy() { super.onDestroy(); - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); } public void onCameraViewStarted(int width, int height) { diff --git a/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java b/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java index c216bea9a..5f0e6c880 100644 --- a/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java +++ b/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java @@ -64,7 +64,8 @@ public class Sample3Native extends Activity implements CvCameraViewListener { @Override public void onPause() { - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); super.onPause(); } @@ -77,7 +78,8 @@ public class Sample3Native extends Activity implements CvCameraViewListener { public void onDestroy() { super.onDestroy(); - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); } public void onCameraViewStarted(int width, int height) { diff --git a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java index c9e745b65..e70f9d68c 100644 --- a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java +++ b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java @@ -90,7 +90,8 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener { @Override public void onPause() { - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); super.onPause(); } @@ -103,7 +104,8 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener { public void onDestroy() { super.onDestroy(); - mOpenCvCameraView.disableView(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); } public void onCameraViewStarted(int width, int height) {