Android samples updated according onCameraFrame callback signature change.

FpsMeter class removed from Image Manipulations and Face Detection examples as unused code.
This commit is contained in:
Alexander Smorkalov 2013-02-01 12:42:21 +04:00
parent 3ef588b877
commit 6b5eac328f
11 changed files with 49 additions and 150 deletions

View File

@ -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());
}
}

View File

@ -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);

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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