Code review issues fixed. Compatibility issues fixed.
This commit is contained in:
parent
6b5eac328f
commit
f8720ec60e
@ -6,6 +6,7 @@ import org.opencv.R;
|
|||||||
import org.opencv.android.Utils;
|
import org.opencv.android.Utils;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.core.Size;
|
import org.opencv.core.Size;
|
||||||
|
import org.opencv.highgui.Highgui;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@ -35,7 +36,7 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
|||||||
|
|
||||||
private int mState = STOPPED;
|
private int mState = STOPPED;
|
||||||
private Bitmap mCacheBitmap;
|
private Bitmap mCacheBitmap;
|
||||||
private CvCameraViewListener mListener;
|
private CvCameraViewListener2 mListener;
|
||||||
private boolean mSurfaceExist;
|
private boolean mSurfaceExist;
|
||||||
private Object mSyncObject = new Object();
|
private Object mSyncObject = new Object();
|
||||||
|
|
||||||
@ -43,6 +44,7 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
|||||||
protected int mFrameHeight;
|
protected int mFrameHeight;
|
||||||
protected int mMaxHeight;
|
protected int mMaxHeight;
|
||||||
protected int mMaxWidth;
|
protected int mMaxWidth;
|
||||||
|
protected int mPreviewFormat = Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA;
|
||||||
protected int mCameraIndex = -1;
|
protected int mCameraIndex = -1;
|
||||||
protected boolean mEnabled;
|
protected boolean mEnabled;
|
||||||
protected FpsMeter mFpsMeter = null;
|
protected FpsMeter mFpsMeter = null;
|
||||||
@ -89,10 +91,71 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
|||||||
* The returned values - is a modified frame which needs to be displayed on the screen.
|
* 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)
|
* TODO: pass the parameters specifying the format of the frame (BPP, YUV or RGB and etc)
|
||||||
*/
|
*/
|
||||||
public Mat onCameraFrame(CvCameraViewFrame inputFrame);
|
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 interface CvCameraViewFrame {
|
||||||
public abstract Mat rgba();
|
public abstract Mat rgba();
|
||||||
public abstract Mat gray();
|
public abstract Mat gray();
|
||||||
@ -168,10 +231,16 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
|||||||
* @param listener
|
* @param listener
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void setCvCameraViewListener(CvCameraViewListener listener) {
|
public void setCvCameraViewListener(CvCameraViewListener2 listener) {
|
||||||
mListener = 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
|
* 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.
|
* size - the biggest size which less or equal the size set will be selected.
|
||||||
@ -186,6 +255,15 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
|||||||
mMaxHeight = maxHeight;
|
mMaxHeight = maxHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetCaptureFormat(int format)
|
||||||
|
{
|
||||||
|
mPreviewFormat = format;
|
||||||
|
if (mListener instanceof CvCameraViewListenerAdapter) {
|
||||||
|
CvCameraViewListenerAdapter adapter = (CvCameraViewListenerAdapter) mListener;
|
||||||
|
adapter.setFrameFormat(mPreviewFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when mSyncObject lock is held
|
* Called when mSyncObject lock is held
|
||||||
*/
|
*/
|
||||||
|
@ -6,7 +6,7 @@ import org.opencv.android.LoaderCallbackInterface;
|
|||||||
import org.opencv.android.OpenCVLoader;
|
import org.opencv.android.OpenCVLoader;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.android.CameraBridgeViewBase;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -17,7 +17,7 @@ import android.view.MotionEvent;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
public class Puzzle15Activity extends Activity implements CvCameraViewListener, View.OnTouchListener {
|
public class Puzzle15Activity extends Activity implements CvCameraViewListener2, View.OnTouchListener {
|
||||||
|
|
||||||
private static final String TAG = "Sample::Puzzle15::Activity";
|
private static final String TAG = "Sample::Puzzle15::Activity";
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import org.opencv.core.Rect;
|
|||||||
import org.opencv.core.Scalar;
|
import org.opencv.core.Scalar;
|
||||||
import org.opencv.core.Size;
|
import org.opencv.core.Size;
|
||||||
import org.opencv.android.CameraBridgeViewBase;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -26,7 +26,7 @@ import android.view.Window;
|
|||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.View.OnTouchListener;
|
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 static final String TAG = "OCVSample::Activity";
|
||||||
|
|
||||||
private boolean mIsColorSelected = false;
|
private boolean mIsColorSelected = false;
|
||||||
|
@ -16,7 +16,7 @@ import org.opencv.core.Rect;
|
|||||||
import org.opencv.core.Scalar;
|
import org.opencv.core.Scalar;
|
||||||
import org.opencv.core.Size;
|
import org.opencv.core.Size;
|
||||||
import org.opencv.android.CameraBridgeViewBase;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||||
import org.opencv.objdetect.CascadeClassifier;
|
import org.opencv.objdetect.CascadeClassifier;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -27,7 +27,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.WindowManager;
|
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 String TAG = "OCVSample::Activity";
|
||||||
private static final Scalar FACE_RECT_COLOR = new Scalar(0, 255, 0, 255);
|
private static final Scalar FACE_RECT_COLOR = new Scalar(0, 255, 0, 255);
|
||||||
|
@ -15,7 +15,7 @@ import org.opencv.core.Point;
|
|||||||
import org.opencv.core.Scalar;
|
import org.opencv.core.Scalar;
|
||||||
import org.opencv.core.Size;
|
import org.opencv.core.Size;
|
||||||
import org.opencv.android.CameraBridgeViewBase;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -25,7 +25,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.WindowManager;
|
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";
|
private static final String TAG = "OCVSample::Activity";
|
||||||
|
|
||||||
public static final int VIEW_MODE_RGBA = 0;
|
public static final int VIEW_MODE_RGBA = 0;
|
||||||
|
@ -6,7 +6,7 @@ import org.opencv.android.LoaderCallbackInterface;
|
|||||||
import org.opencv.android.OpenCVLoader;
|
import org.opencv.android.OpenCVLoader;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.android.CameraBridgeViewBase;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -17,7 +17,7 @@ import android.view.SurfaceView;
|
|||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Toast;
|
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 static final String TAG = "OCVSample::Activity";
|
||||||
|
|
||||||
private CameraBridgeViewBase mOpenCvCameraView;
|
private CameraBridgeViewBase mOpenCvCameraView;
|
||||||
|
@ -10,7 +10,7 @@ import org.opencv.core.Mat;
|
|||||||
import org.opencv.core.Point;
|
import org.opencv.core.Point;
|
||||||
import org.opencv.core.Scalar;
|
import org.opencv.core.Scalar;
|
||||||
import org.opencv.android.CameraBridgeViewBase;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -20,7 +20,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.WindowManager;
|
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";
|
private static final String TAG = "OCVSample::Activity";
|
||||||
|
|
||||||
public static final int VIEW_MODE_RGBA = 0;
|
public static final int VIEW_MODE_RGBA = 0;
|
||||||
|
@ -7,14 +7,14 @@ import org.opencv.android.OpenCVLoader;
|
|||||||
import org.opencv.core.CvType;
|
import org.opencv.core.CvType;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.android.CameraBridgeViewBase;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.WindowManager;
|
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 static final String TAG = "OCVSample::Activity";
|
||||||
|
|
||||||
private Mat mRgba;
|
private Mat mRgba;
|
||||||
|
@ -7,7 +7,7 @@ import org.opencv.android.OpenCVLoader;
|
|||||||
import org.opencv.core.CvType;
|
import org.opencv.core.CvType;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.android.CameraBridgeViewBase;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -17,7 +17,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.WindowManager;
|
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 String TAG = "OCVSample::Activity";
|
||||||
|
|
||||||
private static final int VIEW_MODE_RGBA = 0;
|
private static final int VIEW_MODE_RGBA = 0;
|
||||||
@ -133,13 +133,12 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener {
|
|||||||
// input frame has gray scale format
|
// input frame has gray scale format
|
||||||
mRgba = inputFrame.rgba();
|
mRgba = inputFrame.rgba();
|
||||||
Imgproc.Canny(inputFrame.gray(), mIntermediateMat, 80, 100);
|
Imgproc.Canny(inputFrame.gray(), mIntermediateMat, 80, 100);
|
||||||
Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4);
|
Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2RGBA, 4);
|
||||||
break;
|
break;
|
||||||
case VIEW_MODE_FEATURES:
|
case VIEW_MODE_FEATURES:
|
||||||
// input frame has RGBA format
|
// input frame has RGBA format
|
||||||
mRgba = inputFrame.rgba();
|
mRgba = inputFrame.rgba();
|
||||||
mGray = inputFrame.gray();
|
mGray = inputFrame.gray();
|
||||||
Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGBA2GRAY);
|
|
||||||
FindFeatures(mGray.getNativeObjAddr(), mRgba.getNativeObjAddr());
|
FindFeatures(mGray.getNativeObjAddr(), mRgba.getNativeObjAddr());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
|||||||
import org.opencv.android.LoaderCallbackInterface;
|
import org.opencv.android.LoaderCallbackInterface;
|
||||||
import org.opencv.android.OpenCVLoader;
|
import org.opencv.android.OpenCVLoader;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -28,7 +28,7 @@ import android.view.View.OnTouchListener;
|
|||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Toast;
|
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 static final String TAG = "OCVSample::Activity";
|
||||||
|
|
||||||
private SampleJavaCameraView mOpenCvCameraView;
|
private SampleJavaCameraView mOpenCvCameraView;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user