From 6b5eac328fa2bb2207eef8a2d30eb55ea69f751f Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 1 Feb 2013 12:42:21 +0400 Subject: [PATCH] Android samples updated according onCameraFrame callback signature change. FpsMeter class removed from Image Manipulations and Face Detection examples as unused code. --- .../opencv/samples/puzzle15/Puzzle15Activity.java | 9 ++-- .../ColorBlobDetectionActivity.java | 5 ++- .../org/opencv/samples/facedetect/FdActivity.java | 8 ++-- .../org/opencv/samples/facedetect/FpsMeter.java | 50 ---------------------- .../samples/imagemanipulations/FpsMeter.java | 50 ---------------------- .../ImageManipulationsActivity.java | 7 +-- .../org/opencv/samples/tutorial1/Sample1Java.java | 5 ++- .../samples/tutorial2/Sample2NativeCamera.java | 15 +++---- .../opencv/samples/tutorial3/Sample3Native.java | 16 +++---- .../org/opencv/samples/tutorial4/Sample4Mixed.java | 29 ++++++------- .../samples/tutorial5/Sample5CameraControl.java | 5 ++- 11 files changed, 49 insertions(+), 150 deletions(-) delete mode 100644 samples/android/face-detection/src/org/opencv/samples/facedetect/FpsMeter.java delete mode 100644 samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/FpsMeter.java 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 d196196..d32c46d 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 @@ -1,6 +1,7 @@ package org.opencv.samples.puzzle15; import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.Mat; @@ -109,10 +110,6 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener, public void onCameraViewStopped() { } - public Mat onCameraFrame(Mat inputFrame) { - return mPuzzle15.puzzleFrame(inputFrame); - } - public boolean onTouch(View view, MotionEvent event) { int xpos, ypos; @@ -129,4 +126,8 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener, return false; } + + public Mat onCameraFrame(CvCameraViewFrame inputFrame) { + return mPuzzle15.puzzleFrame(inputFrame.rgba()); + } } 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 13ffc68..c7ac9a2 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 @@ -3,6 +3,7 @@ package org.opencv.samples.colorblobdetect; import java.util.List; import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.Core; @@ -160,8 +161,8 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe return false; // don't need subsequent touch events } - public Mat onCameraFrame(Mat inputFrame) { - inputFrame.copyTo(mRgba); + public Mat onCameraFrame(CvCameraViewFrame inputFrame) { + mRgba = inputFrame.rgba(); if (mIsColorSelected) { mDetector.process(mRgba); diff --git a/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java b/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java index d59de02..333d08b 100644 --- a/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java +++ b/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStream; import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.Core; @@ -16,7 +17,6 @@ import org.opencv.core.Scalar; import org.opencv.core.Size; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; -import org.opencv.imgproc.Imgproc; import org.opencv.objdetect.CascadeClassifier; import android.app.Activity; @@ -157,10 +157,10 @@ public class FdActivity extends Activity implements CvCameraViewListener { mRgba.release(); } - public Mat onCameraFrame(Mat inputFrame) { + public Mat onCameraFrame(CvCameraViewFrame inputFrame) { - inputFrame.copyTo(mRgba); - Imgproc.cvtColor(inputFrame, mGray, Imgproc.COLOR_RGBA2GRAY); + mRgba = inputFrame.rgba(); + mGray = inputFrame.gray(); if (mAbsoluteFaceSize == 0) { int height = mGray.rows(); diff --git a/samples/android/face-detection/src/org/opencv/samples/facedetect/FpsMeter.java b/samples/android/face-detection/src/org/opencv/samples/facedetect/FpsMeter.java deleted file mode 100644 index 2438bf8..0000000 --- a/samples/android/face-detection/src/org/opencv/samples/facedetect/FpsMeter.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.opencv.samples.facedetect; - -import java.text.DecimalFormat; - -import org.opencv.core.Core; - -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.util.Log; - -public class FpsMeter { - private static final String TAG = "OCVSample::FpsMeter"; - int step; - int framesCouner; - double freq; - long prevFrameTime; - String strfps; - DecimalFormat twoPlaces = new DecimalFormat("0.00"); - Paint paint; - - public void init() { - step = 20; - framesCouner = 0; - freq = Core.getTickFrequency(); - prevFrameTime = Core.getTickCount(); - strfps = ""; - - paint = new Paint(); - paint.setColor(Color.BLUE); - paint.setTextSize(50); - } - - public void measure() { - framesCouner++; - if (framesCouner % step == 0) { - long time = Core.getTickCount(); - double fps = step * freq / (time - prevFrameTime); - prevFrameTime = time; - DecimalFormat twoPlaces = new DecimalFormat("0.00"); - strfps = twoPlaces.format(fps) + " FPS"; - Log.i(TAG, strfps); - } - } - - public void draw(Canvas canvas, float offsetx, float offsety) { - canvas.drawText(strfps, 20 + offsetx, 10 + 50 + offsety, paint); - } - -} diff --git a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/FpsMeter.java b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/FpsMeter.java deleted file mode 100644 index 2f80236..0000000 --- a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/FpsMeter.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.opencv.samples.imagemanipulations; - -import java.text.DecimalFormat; - -import org.opencv.core.Core; - -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.util.Log; - -public class FpsMeter { - private static final String TAG = "OCVSample::FpsMeter"; - int step; - int framesCouner; - double freq; - long prevFrameTime; - String strfps; - DecimalFormat twoPlaces = new DecimalFormat("0.00"); - Paint paint; - - public void init() { - step = 20; - framesCouner = 0; - freq = Core.getTickFrequency(); - prevFrameTime = Core.getTickCount(); - strfps = ""; - - paint = new Paint(); - paint.setColor(Color.BLUE); - paint.setTextSize(50); - } - - public void measure() { - framesCouner++; - if (framesCouner % step == 0) { - long time = Core.getTickCount(); - double fps = step * freq / (time - prevFrameTime); - prevFrameTime = time; - DecimalFormat twoPlaces = new DecimalFormat("0.00"); - strfps = twoPlaces.format(fps) + " FPS"; - Log.i(TAG, strfps); - } - } - - public void draw(Canvas canvas, float offsetx, float offsety) { - canvas.drawText(strfps, 20 + offsetx, 10 + 50 + offsety, paint); - } - -} 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 a66145c..513e9b7 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 @@ -3,6 +3,7 @@ package org.opencv.samples.imagemanipulations; import java.util.Arrays; import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.Core; @@ -258,8 +259,8 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView mZoomWindow = null; } - public Mat onCameraFrame(Mat inputFrame) { - inputFrame.copyTo(mRgba); + public Mat onCameraFrame(CvCameraViewFrame inputFrame) { + mRgba = inputFrame.rgba(); switch (ImageManipulationsActivity.viewMode) { case ImageManipulationsActivity.VIEW_MODE_RGBA: @@ -315,7 +316,7 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView break; case ImageManipulationsActivity.VIEW_MODE_SOBEL: - Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGBA2GRAY); + mGray = inputFrame.gray(); if ((mRgbaInnerWindow == null) || (mGrayInnerWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height)) CreateAuxiliaryMats(); 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 9e5150f..65e7cd7 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 @@ -1,6 +1,7 @@ package org.opencv.samples.tutorial1; import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.Mat; @@ -124,7 +125,7 @@ public class Sample1Java extends Activity implements CvCameraViewListener { public void onCameraViewStopped() { } - public Mat onCameraFrame(Mat inputFrame) { - return inputFrame; + public Mat onCameraFrame(CvCameraViewFrame inputFrame) { + return inputFrame.rgba(); } } 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 901e8dd..167d5e0 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 @@ -1,6 +1,7 @@ package org.opencv.samples.tutorial2; import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.Core; @@ -10,7 +11,6 @@ import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; -import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc; import android.app.Activity; @@ -101,20 +101,20 @@ public class Sample2NativeCamera extends Activity implements CvCameraViewListene mIntermediateMat.release(); } - public Mat onCameraFrame(Mat inputFrame) { + public Mat onCameraFrame(CvCameraViewFrame inputFrame) { switch (Sample2NativeCamera.viewMode) { case Sample2NativeCamera.VIEW_MODE_GRAY: { - Imgproc.cvtColor(inputFrame, mRgba, Imgproc.COLOR_GRAY2RGBA, 4); + Imgproc.cvtColor(inputFrame.gray(), mRgba, Imgproc.COLOR_GRAY2RGBA, 4); } break; case Sample2NativeCamera.VIEW_MODE_RGBA: { - inputFrame.copyTo(mRgba); - Core.putText(mRgba, "OpenCV+Android", new Point(10, inputFrame.rows() - 10), 3, 1, new Scalar(255, 0, 0, 255), 2); + mRgba = inputFrame.rgba(); + Core.putText(mRgba, "OpenCV+Android", new Point(10, mRgba.rows() - 10), 3, 1, new Scalar(255, 0, 0, 255), 2); } break; case Sample2NativeCamera.VIEW_MODE_CANNY: { - Imgproc.Canny(inputFrame, mIntermediateMat, 80, 100); + Imgproc.Canny(inputFrame.gray(), mIntermediateMat, 80, 100); Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4); } break; } @@ -136,17 +136,14 @@ public class Sample2NativeCamera extends Activity implements CvCameraViewListene Log.i(TAG, "called onOptionsItemSelected; selected item: " + item); if (item == mItemPreviewRGBA) { - mOpenCvCameraView.SetCaptureFormat(Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA); viewMode = VIEW_MODE_RGBA; } else if (item == mItemPreviewGray) { - mOpenCvCameraView.SetCaptureFormat(Highgui.CV_CAP_ANDROID_GREY_FRAME); viewMode = VIEW_MODE_GRAY; } else if (item == mItemPreviewCanny) { - mOpenCvCameraView.SetCaptureFormat(Highgui.CV_CAP_ANDROID_GREY_FRAME); viewMode = VIEW_MODE_CANNY; } 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 ea7998e..50baab1 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 @@ -1,13 +1,13 @@ package org.opencv.samples.tutorial3; import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; -import org.opencv.imgproc.Imgproc; import android.app.Activity; import android.os.Bundle; @@ -18,7 +18,7 @@ public class Sample3Native extends Activity implements CvCameraViewListener { private static final String TAG = "OCVSample::Activity"; private Mat mRgba; - private Mat mGrayMat; + private Mat mGray; private CameraBridgeViewBase mOpenCvCameraView; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @@ -82,18 +82,18 @@ public class Sample3Native extends Activity implements CvCameraViewListener { public void onCameraViewStarted(int width, int height) { mRgba = new Mat(height, width, CvType.CV_8UC4); - mGrayMat = new Mat(height, width, CvType.CV_8UC1); + mGray = new Mat(height, width, CvType.CV_8UC1); } public void onCameraViewStopped() { mRgba.release(); - mGrayMat.release(); + mGray.release(); } - public Mat onCameraFrame(Mat inputFrame) { - inputFrame.copyTo(mRgba); - Imgproc.cvtColor(mRgba, mGrayMat, Imgproc.COLOR_RGBA2GRAY); - FindFeatures(mGrayMat.getNativeObjAddr(), mRgba.getNativeObjAddr()); + public Mat onCameraFrame(CvCameraViewFrame inputFrame) { + mRgba = inputFrame.rgba(); + mGray = inputFrame.gray(); + FindFeatures(mGray.getNativeObjAddr(), mRgba.getNativeObjAddr()); return mRgba; } 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 a1b455b..d16b735 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 @@ -1,13 +1,13 @@ package org.opencv.samples.tutorial4; import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; -import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc; import android.app.Activity; @@ -28,7 +28,7 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener { private int mViewMode; private Mat mRgba; private Mat mIntermediateMat; - private Mat mGrayMat; + private Mat mGray; private MenuItem mItemPreviewRGBA; private MenuItem mItemPreviewGray; @@ -109,37 +109,38 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener { public void onCameraViewStarted(int width, int height) { mRgba = new Mat(height, width, CvType.CV_8UC4); mIntermediateMat = new Mat(height, width, CvType.CV_8UC4); - mGrayMat = new Mat(height, width, CvType.CV_8UC1); + mGray = new Mat(height, width, CvType.CV_8UC1); } public void onCameraViewStopped() { mRgba.release(); - mGrayMat.release(); + mGray.release(); mIntermediateMat.release(); } - public Mat onCameraFrame(Mat inputFrame) { + public Mat onCameraFrame(CvCameraViewFrame inputFrame) { final int viewMode = mViewMode; - switch (viewMode) { case VIEW_MODE_GRAY: // input frame has gray scale format - Imgproc.cvtColor(inputFrame, mRgba, Imgproc.COLOR_GRAY2RGBA, 4); + Imgproc.cvtColor(inputFrame.gray(), mRgba, Imgproc.COLOR_GRAY2RGBA, 4); break; case VIEW_MODE_RGBA: // input frame has RBGA format - inputFrame.copyTo(mRgba); + mRgba = inputFrame.rgba(); break; case VIEW_MODE_CANNY: // input frame has gray scale format - Imgproc.Canny(inputFrame, mIntermediateMat, 80, 100); + mRgba = inputFrame.rgba(); + Imgproc.Canny(inputFrame.gray(), mIntermediateMat, 80, 100); Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4); break; case VIEW_MODE_FEATURES: // input frame has RGBA format - inputFrame.copyTo(mRgba); - Imgproc.cvtColor(mRgba, mGrayMat, Imgproc.COLOR_RGBA2GRAY); - FindFeatures(mGrayMat.getNativeObjAddr(), mRgba.getNativeObjAddr()); + mRgba = inputFrame.rgba(); + mGray = inputFrame.gray(); + Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGBA2GRAY); + FindFeatures(mGray.getNativeObjAddr(), mRgba.getNativeObjAddr()); break; } @@ -150,17 +151,13 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener { Log.i(TAG, "called onOptionsItemSelected; selected item: " + item); if (item == mItemPreviewRGBA) { - mOpenCvCameraView.SetCaptureFormat(Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA); mViewMode = VIEW_MODE_RGBA; } else if (item == mItemPreviewGray) { - mOpenCvCameraView.SetCaptureFormat(Highgui.CV_CAP_ANDROID_GREY_FRAME); mViewMode = VIEW_MODE_GRAY; } else if (item == mItemPreviewCanny) { - mOpenCvCameraView.SetCaptureFormat(Highgui.CV_CAP_ANDROID_GREY_FRAME); mViewMode = VIEW_MODE_CANNY; } else if (item == mItemPreviewFeatures) { mViewMode = VIEW_MODE_FEATURES; - mOpenCvCameraView.SetCaptureFormat(Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA); } return true; diff --git a/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/Sample5CameraControl.java b/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/Sample5CameraControl.java index 46d038a..9c2f66d 100644 --- a/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/Sample5CameraControl.java +++ b/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/Sample5CameraControl.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.ListIterator; import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.Mat; @@ -102,8 +103,8 @@ public class Sample5CameraControl extends Activity implements CvCameraViewListen public void onCameraViewStopped() { } - public Mat onCameraFrame(Mat inputFrame) { - return inputFrame; + public Mat onCameraFrame(CvCameraViewFrame inputFrame) { + return inputFrame.rgba(); } @Override -- 2.7.4