mirror of https://github.com/opencv/opencv.git
Merge pull request #188 from asmorkalov:app_framework
commit
03f402892d
7 changed files with 189 additions and 39 deletions
@ -0,0 +1,11 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<resources> |
||||
<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> |
@ -0,0 +1,66 @@ |
||||
package org.opencv.android; |
||||
|
||||
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 = "FpsMeter"; |
||||
private static final int STEP = 20; |
||||
private static final DecimalFormat FPS_FORMAT = new DecimalFormat("0.00"); |
||||
|
||||
private int mFramesCouner; |
||||
private double mFrequency; |
||||
private long mprevFrameTime; |
||||
private String mStrfps; |
||||
Paint mPaint; |
||||
boolean mIsInitialized = false; |
||||
int mWidth = 0; |
||||
int mHeight = 0; |
||||
|
||||
public void init() { |
||||
mFramesCouner = 0; |
||||
mFrequency = Core.getTickFrequency(); |
||||
mprevFrameTime = Core.getTickCount(); |
||||
mStrfps = ""; |
||||
|
||||
mPaint = new Paint(); |
||||
mPaint.setColor(Color.BLUE); |
||||
mPaint.setTextSize(20); |
||||
} |
||||
|
||||
public void measure() { |
||||
if (!mIsInitialized) { |
||||
init(); |
||||
mIsInitialized = true; |
||||
} else { |
||||
mFramesCouner++; |
||||
if (mFramesCouner % STEP == 0) { |
||||
long time = Core.getTickCount(); |
||||
double fps = STEP * mFrequency / (time - mprevFrameTime); |
||||
mprevFrameTime = time; |
||||
if (mWidth != 0 && mHeight != 0) |
||||
mStrfps = FPS_FORMAT.format(fps) + " FPS@" + Integer.valueOf(mWidth) + "x" + Integer.valueOf(mHeight); |
||||
else |
||||
mStrfps = FPS_FORMAT.format(fps) + " FPS"; |
||||
Log.i(TAG, mStrfps); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void setResolution(int width, int height) { |
||||
mWidth = width; |
||||
mHeight = height; |
||||
} |
||||
|
||||
public void draw(Canvas canvas, float offsetx, float offsety) { |
||||
Log.d(TAG, mStrfps); |
||||
canvas.drawText(mStrfps, offsetx, offsety, mPaint); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue