adding displaying FPS
This commit is contained in:
parent
0185cb27eb
commit
9ab291ea1c
@ -1,12 +1,16 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="${relativePackage}.${activityClass}" >
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<org.opencv.samples.tutorial4.MyGLSurfaceView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/my_gl_surface_view" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/app_name" />
|
||||
android:id="@+id/fps_text_view"
|
||||
android:text="FPS:" />
|
||||
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
|
@ -6,7 +6,11 @@ import javax.microedition.khronos.opengles.GL10;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public abstract class MyGLRendererBase implements GLSurfaceView.Renderer, SurfaceTexture.OnFrameAvailableListener {
|
||||
protected final String LOGTAG = "MyGLRendererBase";
|
||||
@ -15,6 +19,7 @@ public abstract class MyGLRendererBase implements GLSurfaceView.Renderer, Surfac
|
||||
|
||||
protected SurfaceTexture mSTex;
|
||||
protected MyGLSurfaceView mView;
|
||||
protected TextView mFpsText;
|
||||
|
||||
protected boolean mGLInit = false;
|
||||
protected boolean mTexUpdate = false;
|
||||
@ -27,6 +32,11 @@ public abstract class MyGLRendererBase implements GLSurfaceView.Renderer, Surfac
|
||||
protected abstract void closeCamera();
|
||||
protected abstract void setCameraPreviewSize(int width, int height);
|
||||
|
||||
public void setFpsTextView(TextView fpsTV)
|
||||
{
|
||||
mFpsText = fpsTV;
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
Log.i(LOGTAG, "onResume");
|
||||
frameCounter = 0;
|
||||
@ -70,8 +80,16 @@ public abstract class MyGLRendererBase implements GLSurfaceView.Renderer, Surfac
|
||||
frameCounter++;
|
||||
if(frameCounter >= 10)
|
||||
{
|
||||
int fps = (int) (frameCounter * 1e9 / (System.nanoTime() - lastNanoTime));
|
||||
final int fps = (int) (frameCounter * 1e9 / (System.nanoTime() - lastNanoTime));
|
||||
Log.i(LOGTAG, "drawFrame() FPS: "+fps);
|
||||
if(mFpsText != null) {
|
||||
Runnable fpsUpdater = new Runnable() {
|
||||
public void run() {
|
||||
mFpsText.setText("FPS: " + fps);
|
||||
}
|
||||
};
|
||||
new Handler(Looper.getMainLooper()).post(fpsUpdater);
|
||||
}
|
||||
frameCounter = 0;
|
||||
lastNanoTime = System.nanoTime();
|
||||
}
|
||||
|
@ -2,14 +2,16 @@ package org.opencv.samples.tutorial4;
|
||||
|
||||
import android.content.Context;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.widget.TextView;
|
||||
|
||||
class MyGLSurfaceView extends GLSurfaceView {
|
||||
public class MyGLSurfaceView extends GLSurfaceView {
|
||||
|
||||
MyGLRendererBase mRenderer;
|
||||
|
||||
MyGLSurfaceView(Context context) {
|
||||
super(context);
|
||||
public MyGLSurfaceView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
if(android.os.Build.VERSION.SDK_INT >= 21)
|
||||
mRenderer = new Camera2Renderer(this);
|
||||
@ -21,6 +23,10 @@ class MyGLSurfaceView extends GLSurfaceView {
|
||||
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
|
||||
}
|
||||
|
||||
public void setFpsTextView(TextView tv) {
|
||||
mRenderer.setFpsTextView(tv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
super.surfaceCreated(holder);
|
||||
|
@ -5,6 +5,7 @@ import android.content.pm.ActivityInfo;
|
||||
import android.os.Bundle;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Tutorial4Activity extends Activity {
|
||||
|
||||
@ -20,8 +21,12 @@ public class Tutorial4Activity extends Activity {
|
||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
|
||||
mView = new MyGLSurfaceView(this);
|
||||
setContentView(mView);
|
||||
//mView = new MyGLSurfaceView(this, null);
|
||||
//setContentView(mView);
|
||||
setContentView(R.layout.activity);
|
||||
mView = (MyGLSurfaceView) findViewById(R.id.my_gl_surface_view);
|
||||
TextView tv = (TextView)findViewById(R.id.fps_text_view);
|
||||
mView.setFpsTextView(tv);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user