<?xml version="1.0" encoding="utf-8"?>
<resources>
- <attr name="show_fps" format="boolean"/>
- <attr name="camera_index" format="integer"/>
-</resources>
\ No newline at end of file
+ <declare-styleable name = "CameraBridgeViewBase" >
+ <attr name="show_fps" format="boolean"/>
+ <attr name="camera_id" format="integer" >
+ <enum name="any" value="-1" />
+ <enum name="back" value="0" />
+ <enum name="front" value="1" />
+ </attr>
+ </declare-styleable>
+</resources>
import java.util.List;
+import org.opencv.R;
import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.AttributeSet;
private Object mSyncObject = new Object();
+ public CameraBridgeViewBase(Context context, int cameraId) {
+ super(context);
+ mCameraIndex = cameraId;
+ }
+
public CameraBridgeViewBase(Context context, AttributeSet attrs) {
super(context, attrs);
- if (attrs.getAttributeBooleanValue(null, "show_fps", false))
+
+ int count = attrs.getAttributeCount();
+ Log.d(TAG, "Attr count: " + Integer.valueOf(count));
+
+ TypedArray tmp = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase);
+ if (tmp.getBoolean(R.styleable.CameraBridgeViewBase_show_fps, false))
enableFpsMeter();
- mCameraIndex = attrs.getAttributeIntValue(null,"camera_index", -1);
+ mCameraIndex = tmp.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1);
getHolder().addCallback(this);
mMaxWidth = MAX_UNSPECIFIED;
public void enableFpsMeter() {
if (mFpsMeter == null) {
mFpsMeter = new FpsMeter();
+ mFpsMeter.setResolution(mFrameWidth, mFrameHeight);
}
}
DecimalFormat twoPlaces = new DecimalFormat("0.00");
Paint paint;
boolean isInitialized = false;
+ int mWidth = 0;
+ int mHeight = 0;
public void init() {
step = 20;
double fps = step * freq / (time - prevFrameTime);
prevFrameTime = time;
DecimalFormat twoPlaces = new DecimalFormat("0.00");
- strfps = twoPlaces.format(fps) + " FPS";
+ if (mWidth != 0 && mHeight != 0)
+ strfps = twoPlaces.format(fps) + " FPS@" + Integer.valueOf(mWidth) + "x" + Integer.valueOf(mHeight);
+ else
+ strfps = twoPlaces.format(fps) + " FPS";
Log.i(TAG, strfps);
}
}
}
+ public void setResolution(int width, int height) {
+ mWidth = width;
+ mHeight = height;
+ }
+
public void draw(Canvas canvas, float offsetx, float offsety) {
Log.d(TAG, strfps);
canvas.drawText(strfps, 20 + offsetx, 10 + 50 + offsety, paint);
}
}
+ public JavaCameraView(Context context, int cameraId) {
+ super(context, cameraId);
+ }
+
public JavaCameraView(Context context, AttributeSet attrs) {
super(context, attrs);
Log.d(TAG, "Java camera view ctor");
mFrameWidth = params.getPreviewSize().width;
mFrameHeight = params.getPreviewSize().height;
+ if (mFpsMeter != null) {
+ mFpsMeter.setResolution(mFrameWidth, mFrameHeight);
+ }
+
int size = mFrameWidth * mFrameHeight;
size = size * ImageFormat.getBitsPerPixel(params.getPreviewFormat()) / 8;
mBuffer = new byte[size];
protected VideoCapture mCamera;
+ public NativeCameraView(Context context, int cameraId) {
+ super(context, cameraId);
+ }
+
public NativeCameraView(Context context, AttributeSet attrs) {
super(context, attrs);
}
mFrameWidth = (int)frameSize.width;
mFrameHeight = (int)frameSize.height;
+ if (mFpsMeter != null) {
+ mFpsMeter.setResolution(mFrameWidth, mFrameHeight);
+ }
+
AllocateCache();
mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, frameSize.width);