import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.core.Size;
+import org.opencv.highgui.Highgui;
import android.app.Activity;
import android.app.AlertDialog;
private int mState = STOPPED;
private Bitmap mCacheBitmap;
- private CvCameraViewListener mListener;
+ private CvCameraViewListener2 mListener;
private boolean mSurfaceExist;
private Object mSyncObject = new Object();
protected int mFrameHeight;
protected int mMaxHeight;
protected int mMaxWidth;
+ protected int mPreviewFormat = Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA;
protected int mCameraIndex = -1;
protected boolean mEnabled;
protected FpsMeter mFpsMeter = null;
* 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(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();
* @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.
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
*/
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.os.Bundle;
import android.app.Activity;
import android.view.View;
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";
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;
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;
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.objdetect.CascadeClassifier;
import android.app.Activity;
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);
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;
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;
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;
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;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
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;
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;
import org.opencv.core.CvType;
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;
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;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
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;
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;
// input frame has gray scale format
mRgba = inputFrame.rgba();
Imgproc.Canny(inputFrame.gray(), mIntermediateMat, 80, 100);
- Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4);
+ Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2RGBA, 4);
break;
case VIEW_MODE_FEATURES:
// input frame has RGBA format
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
- Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGBA2GRAY);
FindFeatures(mGray.getNativeObjAddr(), mRgba.getNativeObjAddr());
break;
}
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;
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;