mirror of
https://github.com/opencv/opencv.git
synced 2024-11-27 20:50:25 +08:00
Modified Android samples
This commit is contained in:
parent
87ad9b1c3e
commit
f97e5f7353
@ -50,7 +50,7 @@ class Sample1View extends SampleViewBase implements SurfaceHolder.Callback {
|
||||
@Override
|
||||
protected Bitmap processFrame(byte[] data)
|
||||
{
|
||||
Log.e("SAMP1", "processFrame begin");
|
||||
//Log.e("SAMP1", "processFrame begin");
|
||||
|
||||
mYuv.put(0, 0, data);
|
||||
|
||||
@ -83,7 +83,7 @@ class Sample1View extends SampleViewBase implements SurfaceHolder.Callback {
|
||||
Bitmap bmp = Bitmap.createBitmap(mFrameWidth, mFrameHeight, Bitmap.Config.ARGB_8888);
|
||||
android.MatToBitmap(mRgba, bmp);
|
||||
|
||||
Log.e("SAMP1", "processFrame end");
|
||||
//Log.e("SAMP1", "processFrame end");
|
||||
return bmp;
|
||||
}
|
||||
|
||||
|
@ -52,15 +52,16 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
|
||||
}
|
||||
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
Log.i("SAMP1", "surfaceCreated");
|
||||
mCamera = Camera.open();
|
||||
mCamera.setPreviewCallback(
|
||||
new PreviewCallback() {
|
||||
public void onPreviewFrame(byte[] data, Camera camera) {
|
||||
synchronized(SampleViewBase.this) {
|
||||
mFrame = data;
|
||||
Log.i("SAMP1", "before notify");
|
||||
//Log.i("SAMP1", "before notify");
|
||||
SampleViewBase.this.notify();
|
||||
Log.i("SAMP1", "after notify");
|
||||
//Log.i("SAMP1", "after notify");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,6 +70,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
|
||||
}
|
||||
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
Log.i("SAMP1", "surfaceDestroyed");
|
||||
mThreadRun = false;
|
||||
if(mCamera != null) {
|
||||
synchronized(this) {
|
||||
@ -87,22 +89,26 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
|
||||
Log.i(TAG, "Starting thread");
|
||||
Bitmap bmp = null;
|
||||
while(mThreadRun) {
|
||||
Log.i("SAMP1", "before synchronized");
|
||||
//Log.i("SAMP1", "before synchronized");
|
||||
synchronized(this) {
|
||||
Log.i("SAMP1", "in synchronized");
|
||||
//Log.i("SAMP1", "in synchronized");
|
||||
try {
|
||||
this.wait();
|
||||
Log.i("SAMP1", "before processFrame");
|
||||
//Log.i("SAMP1", "before processFrame");
|
||||
bmp = processFrame(mFrame);
|
||||
Log.i("SAMP1", "after processFrame");
|
||||
//Log.i("SAMP1", "after processFrame");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Canvas canvas = mHolder.lockCanvas();
|
||||
canvas.drawBitmap(bmp, (canvas.getWidth()-mFrameWidth)/2, (canvas.getHeight()-mFrameHeight)/2, null);
|
||||
mHolder.unlockCanvasAndPost(canvas);
|
||||
if (bmp != null){
|
||||
Canvas canvas = mHolder.lockCanvas();
|
||||
if (canvas != null){
|
||||
canvas.drawBitmap(bmp, (canvas.getWidth()-mFrameWidth)/2, (canvas.getHeight()-mFrameHeight)/2, null);
|
||||
mHolder.unlockCanvasAndPost(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user