mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 06:03:15 +08:00
Merge pull request #402 from asmorkalov:samples_data_rase_fix
This commit is contained in:
commit
504264ab7b
@ -36,7 +36,7 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
||||
|
||||
private int mState = STOPPED;
|
||||
private Bitmap mCacheBitmap;
|
||||
private CvCameraViewListener mListener;
|
||||
private CvCameraViewListener2 mListener;
|
||||
private boolean mSurfaceExist;
|
||||
private Object mSyncObject = new Object();
|
||||
|
||||
@ -92,9 +92,75 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
||||
* TODO: pass the parameters specifying the format of the frame (BPP, YUV or RGB and etc)
|
||||
*/
|
||||
public Mat onCameraFrame(Mat inputFrame);
|
||||
|
||||
}
|
||||
|
||||
public interface CvCameraViewListener2 {
|
||||
/**
|
||||
* This method is invoked when camera preview has started. After this method is invoked
|
||||
* the frames will start to be delivered to client via the onCameraFrame() callback.
|
||||
* @param width - the width of the frames that will be delivered
|
||||
* @param height - the height of the frames that will be delivered
|
||||
*/
|
||||
public void onCameraViewStarted(int width, int height);
|
||||
|
||||
/**
|
||||
* This method is invoked when camera preview has been stopped for some reason.
|
||||
* No frames will be delivered via onCameraFrame() callback after this method is called.
|
||||
*/
|
||||
public void onCameraViewStopped();
|
||||
|
||||
/**
|
||||
* This method is invoked when delivery of the frame needs to be done.
|
||||
* The returned values - is a modified frame which needs to be displayed on the screen.
|
||||
* TODO: pass the parameters specifying the format of the frame (BPP, YUV or RGB and etc)
|
||||
*/
|
||||
public Mat onCameraFrame(CvCameraViewFrame inputFrame);
|
||||
};
|
||||
|
||||
protected class CvCameraViewListenerAdapter implements CvCameraViewListener2 {
|
||||
public CvCameraViewListenerAdapter(CvCameraViewListener oldStypeListener) {
|
||||
mOldStyleListener = oldStypeListener;
|
||||
}
|
||||
|
||||
public void onCameraViewStarted(int width, int height) {
|
||||
mOldStyleListener.onCameraViewStarted(width, height);
|
||||
}
|
||||
|
||||
public void onCameraViewStopped() {
|
||||
mOldStyleListener.onCameraViewStopped();
|
||||
}
|
||||
|
||||
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
|
||||
Mat result = null;
|
||||
switch (mPreviewFormat) {
|
||||
case Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA:
|
||||
result = mOldStyleListener.onCameraFrame(inputFrame.rgba());
|
||||
break;
|
||||
case Highgui.CV_CAP_ANDROID_GREY_FRAME:
|
||||
result = mOldStyleListener.onCameraFrame(inputFrame.gray());
|
||||
break;
|
||||
default:
|
||||
Log.e(TAG, "Invalid frame format! Only RGBA and Gray Scale are supported!");
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setFrameFormat(int format) {
|
||||
mPreviewFormat = format;
|
||||
}
|
||||
|
||||
private CvCameraViewListenerAdapter() {}
|
||||
|
||||
private int mPreviewFormat = Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA;
|
||||
private CvCameraViewListener mOldStyleListener;
|
||||
};
|
||||
|
||||
public interface CvCameraViewFrame {
|
||||
public abstract Mat rgba();
|
||||
public abstract Mat gray();
|
||||
};
|
||||
|
||||
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
|
||||
Log.d(TAG, "call surfaceChanged event");
|
||||
synchronized(mSyncObject) {
|
||||
@ -165,10 +231,16 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
||||
* @param listener
|
||||
*/
|
||||
|
||||
public void setCvCameraViewListener(CvCameraViewListener listener) {
|
||||
public void setCvCameraViewListener(CvCameraViewListener2 listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public void setCvCameraViewListener(CvCameraViewListener listener) {
|
||||
CvCameraViewListenerAdapter adapter = new CvCameraViewListenerAdapter(listener);
|
||||
adapter.setFrameFormat(mPreviewFormat);
|
||||
mListener = adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the maximum size that camera frame is allowed to be. When selecting
|
||||
* size - the biggest size which less or equal the size set will be selected.
|
||||
@ -186,6 +258,10 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
||||
public void SetCaptureFormat(int format)
|
||||
{
|
||||
mPreviewFormat = format;
|
||||
if (mListener instanceof CvCameraViewListenerAdapter) {
|
||||
CvCameraViewListenerAdapter adapter = (CvCameraViewListenerAdapter) mListener;
|
||||
adapter.setFrameFormat(mPreviewFormat);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,13 +352,13 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
||||
* then displayed on the screen.
|
||||
* @param frame - the current frame to be delivered
|
||||
*/
|
||||
protected void deliverAndDrawFrame(Mat frame) {
|
||||
protected void deliverAndDrawFrame(CvCameraViewFrame frame) {
|
||||
Mat modified;
|
||||
|
||||
if (mListener != null) {
|
||||
modified = mListener.onCameraFrame(frame);
|
||||
} else {
|
||||
modified = frame;
|
||||
modified = frame.rgba();
|
||||
}
|
||||
|
||||
boolean bmpValid = true;
|
||||
|
@ -16,7 +16,6 @@ import android.view.SurfaceHolder;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.highgui.Highgui;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
/**
|
||||
@ -33,7 +32,6 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
|
||||
private static final int MAGIC_TEXTURE_ID = 10;
|
||||
private static final String TAG = "JavaCameraView";
|
||||
|
||||
private Mat mBaseMat;
|
||||
private byte mBuffer[];
|
||||
private Mat[] mFrameChain;
|
||||
private int mChainIdx = 0;
|
||||
@ -41,7 +39,7 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
|
||||
private boolean mStopThread;
|
||||
|
||||
protected Camera mCamera;
|
||||
|
||||
protected JavaCameraFrame mCameraFrame;
|
||||
private SurfaceTexture mSurfaceTexture;
|
||||
|
||||
public static class JavaCameraSizeAccessor implements ListItemAccessor {
|
||||
@ -146,14 +144,14 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
|
||||
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();
|
||||
mFrameChain[0] = new Mat(mFrameHeight + (mFrameHeight/2), mFrameWidth, CvType.CV_8UC1);
|
||||
mFrameChain[1] = new Mat(mFrameHeight + (mFrameHeight/2), mFrameWidth, CvType.CV_8UC1);
|
||||
|
||||
AllocateCache();
|
||||
|
||||
mCameraFrame = new JavaCameraFrame(mFrameChain[mChainIdx], mFrameWidth, mFrameHeight);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
mSurfaceTexture = new SurfaceTexture(MAGIC_TEXTURE_ID);
|
||||
getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
||||
@ -183,12 +181,12 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
|
||||
mCamera.release();
|
||||
}
|
||||
mCamera = null;
|
||||
if (mBaseMat != null)
|
||||
mBaseMat.release();
|
||||
if (mFrameChain != null) {
|
||||
mFrameChain[0].release();
|
||||
mFrameChain[1].release();
|
||||
}
|
||||
if (mCameraFrame != null)
|
||||
mCameraFrame.release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,13 +240,45 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
|
||||
Log.i(TAG, "Frame size is " + frame.length);
|
||||
synchronized (this)
|
||||
{
|
||||
mBaseMat.put(0, 0, frame);
|
||||
mFrameChain[1 - mChainIdx].put(0, 0, frame);
|
||||
this.notify();
|
||||
}
|
||||
if (mCamera != null)
|
||||
mCamera.addCallbackBuffer(mBuffer);
|
||||
}
|
||||
|
||||
private class JavaCameraFrame implements CvCameraViewFrame
|
||||
{
|
||||
public Mat gray() {
|
||||
return mYuvFrameData.submat(0, mHeight, 0, mWidth);
|
||||
}
|
||||
|
||||
public Mat rgba() {
|
||||
Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2BGR_NV12, 4);
|
||||
return mRgba;
|
||||
}
|
||||
|
||||
public JavaCameraFrame(Mat Yuv420sp, int width, int height) {
|
||||
super();
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
mYuvFrameData = Yuv420sp;
|
||||
mRgba = new Mat();
|
||||
}
|
||||
|
||||
public void release() {
|
||||
mRgba.release();
|
||||
}
|
||||
|
||||
private JavaCameraFrame(CvCameraViewFrame obj) {
|
||||
}
|
||||
|
||||
private Mat mYuvFrameData;
|
||||
private Mat mRgba;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
};
|
||||
|
||||
private class CameraWorker implements Runnable {
|
||||
|
||||
public void run() {
|
||||
@ -263,18 +293,8 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
|
||||
}
|
||||
|
||||
if (!mStopThread) {
|
||||
switch (mPreviewFormat) {
|
||||
case Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA:
|
||||
Imgproc.cvtColor(mBaseMat, mFrameChain[mChainIdx], Imgproc.COLOR_YUV2RGBA_NV21, 4);
|
||||
break;
|
||||
case Highgui.CV_CAP_ANDROID_GREY_FRAME:
|
||||
mFrameChain[mChainIdx] = mBaseMat.submat(0, mFrameHeight, 0, mFrameWidth);
|
||||
break;
|
||||
default:
|
||||
Log.e(TAG, "Invalid frame format! Only RGBA and Gray Scale are supported!");
|
||||
};
|
||||
if (!mFrameChain[mChainIdx].empty())
|
||||
deliverAndDrawFrame(mFrameChain[mChainIdx]);
|
||||
deliverAndDrawFrame(mCameraFrame);
|
||||
mChainIdx = 1 - mChainIdx;
|
||||
}
|
||||
} while (!mStopThread);
|
||||
|
@ -125,6 +125,31 @@ public class NativeCameraView extends CameraBridgeViewBase {
|
||||
}
|
||||
}
|
||||
|
||||
private class NativeCameraFrame implements CvCameraViewFrame {
|
||||
|
||||
@Override
|
||||
public Mat rgba() {
|
||||
mCamera.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
return mRgba;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mat gray() {
|
||||
mCamera.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
|
||||
return mGray;
|
||||
}
|
||||
|
||||
public NativeCameraFrame(VideoCapture capture) {
|
||||
mCapture = capture;
|
||||
mGray = new Mat();
|
||||
mRgba = new Mat();
|
||||
}
|
||||
|
||||
private VideoCapture mCapture;
|
||||
private Mat mRgba;
|
||||
private Mat mGray;
|
||||
};
|
||||
|
||||
private class CameraWorker implements Runnable {
|
||||
|
||||
private Mat mRgba = new Mat();
|
||||
@ -137,22 +162,9 @@ public class NativeCameraView extends CameraBridgeViewBase {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (mPreviewFormat) {
|
||||
case Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA:
|
||||
{
|
||||
mCamera.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
deliverAndDrawFrame(mRgba);
|
||||
} break;
|
||||
case Highgui.CV_CAP_ANDROID_GREY_FRAME:
|
||||
mCamera.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
|
||||
deliverAndDrawFrame(mGray);
|
||||
break;
|
||||
default:
|
||||
Log.e(TAG, "Invalid frame format! Only RGBA and Gray Scale are supported!");
|
||||
}
|
||||
deliverAndDrawFrame(new NativeCameraFrame(mCamera));
|
||||
|
||||
} while (!mStopThread);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,9 +63,9 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener,
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.disableView();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -109,10 +109,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 +125,8 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener,
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Mat onCameraFrame(Mat inputFrame) {
|
||||
return mPuzzle15.puzzleFrame(inputFrame);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -13,7 +14,7 @@ import org.opencv.core.Rect;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.android.CameraBridgeViewBase;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import android.app.Activity;
|
||||
@ -25,7 +26,7 @@ import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.View.OnTouchListener;
|
||||
|
||||
public class ColorBlobDetectionActivity extends Activity implements OnTouchListener, CvCameraViewListener {
|
||||
public class ColorBlobDetectionActivity extends Activity implements OnTouchListener, CvCameraViewListener2 {
|
||||
private static final String TAG = "OCVSample::Activity";
|
||||
|
||||
private boolean mIsColorSelected = false;
|
||||
@ -78,9 +79,9 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.disableView();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -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);
|
||||
|
@ -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;
|
||||
@ -15,8 +16,7 @@ import org.opencv.core.Rect;
|
||||
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.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
import org.opencv.objdetect.CascadeClassifier;
|
||||
|
||||
import android.app.Activity;
|
||||
@ -27,7 +27,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class FdActivity extends Activity implements CvCameraViewListener {
|
||||
public class FdActivity extends Activity implements CvCameraViewListener2 {
|
||||
|
||||
private static final String TAG = "OCVSample::Activity";
|
||||
private static final Scalar FACE_RECT_COLOR = new Scalar(0, 255, 0, 255);
|
||||
@ -130,9 +130,9 @@ public class FdActivity extends Activity implements CvCameraViewListener {
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.disableView();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
@ -14,7 +15,7 @@ import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.android.CameraBridgeViewBase;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import android.app.Activity;
|
||||
@ -24,7 +25,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class ImageManipulationsActivity extends Activity implements CvCameraViewListener {
|
||||
public class ImageManipulationsActivity extends Activity implements CvCameraViewListener2 {
|
||||
private static final String TAG = "OCVSample::Activity";
|
||||
|
||||
public static final int VIEW_MODE_RGBA = 0;
|
||||
@ -111,9 +112,9 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.disableView();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -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();
|
||||
|
@ -1,11 +1,12 @@
|
||||
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;
|
||||
import org.opencv.android.CameraBridgeViewBase;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
@ -16,7 +17,7 @@ import android.view.SurfaceView;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class Sample1Java extends Activity implements CvCameraViewListener {
|
||||
public class Sample1Java extends Activity implements CvCameraViewListener2 {
|
||||
private static final String TAG = "OCVSample::Activity";
|
||||
|
||||
private CameraBridgeViewBase mOpenCvCameraView;
|
||||
@ -66,9 +67,9 @@ public class Sample1Java extends Activity implements CvCameraViewListener {
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.disableView();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -9,8 +10,7 @@ import org.opencv.core.Mat;
|
||||
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.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import android.app.Activity;
|
||||
@ -20,7 +20,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class Sample2NativeCamera extends Activity implements CvCameraViewListener {
|
||||
public class Sample2NativeCamera extends Activity implements CvCameraViewListener2 {
|
||||
private static final String TAG = "OCVSample::Activity";
|
||||
|
||||
public static final int VIEW_MODE_RGBA = 0;
|
||||
@ -73,9 +73,9 @@ public class Sample2NativeCamera extends Activity implements CvCameraViewListene
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.disableView();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
@ -1,24 +1,24 @@
|
||||
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 org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class Sample3Native extends Activity implements CvCameraViewListener {
|
||||
public class Sample3Native extends Activity implements CvCameraViewListener2 {
|
||||
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) {
|
||||
@ -62,9 +62,9 @@ public class Sample3Native extends Activity implements CvCameraViewListener {
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.disableView();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import android.app.Activity;
|
||||
@ -17,7 +17,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class Sample4Mixed extends Activity implements CvCameraViewListener {
|
||||
public class Sample4Mixed extends Activity implements CvCameraViewListener2 {
|
||||
private static final String TAG = "OCVSample::Activity";
|
||||
|
||||
private static final int VIEW_MODE_RGBA = 0;
|
||||
@ -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;
|
||||
@ -88,9 +88,9 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener {
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.disableView();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -109,37 +109,37 @@ 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);
|
||||
Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4);
|
||||
mRgba = inputFrame.rgba();
|
||||
Imgproc.Canny(inputFrame.gray(), mIntermediateMat, 80, 100);
|
||||
Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2RGBA, 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();
|
||||
FindFeatures(mGray.getNativeObjAddr(), mRgba.getNativeObjAddr());
|
||||
break;
|
||||
}
|
||||
|
||||
@ -150,17 +150,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;
|
||||
|
@ -6,10 +6,11 @@ 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;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
@ -27,7 +28,7 @@ import android.view.View.OnTouchListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class Sample5CameraControl extends Activity implements CvCameraViewListener, OnTouchListener {
|
||||
public class Sample5CameraControl extends Activity implements CvCameraViewListener2, OnTouchListener {
|
||||
private static final String TAG = "OCVSample::Activity";
|
||||
|
||||
private SampleJavaCameraView mOpenCvCameraView;
|
||||
@ -78,9 +79,9 @@ public class Sample5CameraControl extends Activity implements CvCameraViewListen
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.disableView();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user