Code review issues fixed. Compatibility issues fixed.
This commit is contained in:
@@ -6,6 +6,7 @@ import org.opencv.R;
|
||||
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;
|
||||
@@ -35,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();
|
||||
|
||||
@@ -43,6 +44,7 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
||||
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;
|
||||
@@ -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.
|
||||
* 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 abstract Mat rgba();
|
||||
public abstract Mat gray();
|
||||
@@ -168,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 +255,15 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
||||
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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user