mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 05:29:54 +08:00
Tutorial 1 updated. Execution time camera switching implemented.
Some unification done to simplify camera switching.
This commit is contained in:
parent
016b2cadb0
commit
83d8bc8c55
@ -85,6 +85,7 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
|||||||
private Object mSyncObject = new Object();
|
private Object mSyncObject = new Object();
|
||||||
|
|
||||||
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
|
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
|
||||||
|
Log.d(TAG, "call surfaceChanged event");
|
||||||
synchronized(mSyncObject) {
|
synchronized(mSyncObject) {
|
||||||
if (!mSurfaceExist) {
|
if (!mSurfaceExist) {
|
||||||
mSurfaceExist = true;
|
mSurfaceExist = true;
|
||||||
@ -163,7 +164,7 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
|||||||
private void checkCurrentState() {
|
private void checkCurrentState() {
|
||||||
int targetState;
|
int targetState;
|
||||||
|
|
||||||
if (mEnabled && mSurfaceExist) {
|
if (mEnabled && mSurfaceExist && getVisibility() == VISIBLE) {
|
||||||
targetState = STARTED;
|
targetState = STARTED;
|
||||||
} else {
|
} else {
|
||||||
targetState = STOPPED;
|
targetState = STOPPED;
|
||||||
|
@ -4,8 +4,8 @@ import org.opencv.android.BaseLoaderCallback;
|
|||||||
import org.opencv.android.LoaderCallbackInterface;
|
import org.opencv.android.LoaderCallbackInterface;
|
||||||
import org.opencv.android.OpenCVLoader;
|
import org.opencv.android.OpenCVLoader;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||||
import org.opencv.android.JavaCameraView;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -20,7 +20,7 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener,
|
|||||||
|
|
||||||
private static final String TAG = "Sample::Puzzle15::Activity";
|
private static final String TAG = "Sample::Puzzle15::Activity";
|
||||||
|
|
||||||
private JavaCameraView mOpenCvCameraView;
|
private CameraBridgeViewBase mOpenCvCameraView;
|
||||||
private Puzzle15Processor mPuzzle15;
|
private Puzzle15Processor mPuzzle15;
|
||||||
|
|
||||||
private int mGameWidth;
|
private int mGameWidth;
|
||||||
@ -54,7 +54,7 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener,
|
|||||||
|
|
||||||
setContentView(R.layout.activity_puzzle15);
|
setContentView(R.layout.activity_puzzle15);
|
||||||
|
|
||||||
mOpenCvCameraView = (JavaCameraView) findViewById(R.id.puzzle_activity_surface_view);
|
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.puzzle_activity_surface_view);
|
||||||
mOpenCvCameraView.setCvCameraViewListener(this);
|
mOpenCvCameraView.setCvCameraViewListener(this);
|
||||||
mPuzzle15 = new Puzzle15Processor();
|
mPuzzle15 = new Puzzle15Processor();
|
||||||
mPuzzle15.prepareNewGame();
|
mPuzzle15.prepareNewGame();
|
||||||
|
@ -12,8 +12,8 @@ import org.opencv.core.MatOfPoint;
|
|||||||
import org.opencv.core.Rect;
|
import org.opencv.core.Rect;
|
||||||
import org.opencv.core.Scalar;
|
import org.opencv.core.Scalar;
|
||||||
import org.opencv.core.Size;
|
import org.opencv.core.Size;
|
||||||
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||||
import org.opencv.android.JavaCameraView;
|
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -37,7 +37,7 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe
|
|||||||
private Size SPECTRUM_SIZE;
|
private Size SPECTRUM_SIZE;
|
||||||
private Scalar CONTOUR_COLOR;
|
private Scalar CONTOUR_COLOR;
|
||||||
|
|
||||||
private JavaCameraView mOpenCvCameraView;
|
private CameraBridgeViewBase mOpenCvCameraView;
|
||||||
|
|
||||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||||
@Override
|
@Override
|
||||||
@ -71,7 +71,7 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe
|
|||||||
|
|
||||||
setContentView(R.layout.color_blob_detection_surface_view);
|
setContentView(R.layout.color_blob_detection_surface_view);
|
||||||
|
|
||||||
mOpenCvCameraView = (JavaCameraView)findViewById(R.id.color_blob_detection_activity_surface_view);
|
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.color_blob_detection_activity_surface_view);
|
||||||
mOpenCvCameraView.setCvCameraViewListener(this);
|
mOpenCvCameraView.setCvCameraViewListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import org.opencv.core.MatOfRect;
|
|||||||
import org.opencv.core.Rect;
|
import org.opencv.core.Rect;
|
||||||
import org.opencv.core.Scalar;
|
import org.opencv.core.Scalar;
|
||||||
import org.opencv.core.Size;
|
import org.opencv.core.Size;
|
||||||
import org.opencv.android.JavaCameraView;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
import org.opencv.objdetect.CascadeClassifier;
|
import org.opencv.objdetect.CascadeClassifier;
|
||||||
@ -53,7 +53,7 @@ public class FdActivity extends Activity implements CvCameraViewListener {
|
|||||||
private float mRelativeFaceSize = 0;
|
private float mRelativeFaceSize = 0;
|
||||||
private int mAbsoluteFaceSize = 0;
|
private int mAbsoluteFaceSize = 0;
|
||||||
|
|
||||||
private JavaCameraView mOpenCvCameraView;
|
private CameraBridgeViewBase mOpenCvCameraView;
|
||||||
|
|
||||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||||
@Override
|
@Override
|
||||||
@ -125,7 +125,7 @@ public class FdActivity extends Activity implements CvCameraViewListener {
|
|||||||
|
|
||||||
setContentView(R.layout.face_detect_surface_view);
|
setContentView(R.layout.face_detect_surface_view);
|
||||||
|
|
||||||
mOpenCvCameraView = (JavaCameraView)findViewById(R.id.fd_activity_surface_view);
|
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.fd_activity_surface_view);
|
||||||
mOpenCvCameraView.setCvCameraViewListener(this);
|
mOpenCvCameraView.setCvCameraViewListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import org.opencv.core.MatOfInt;
|
|||||||
import org.opencv.core.Point;
|
import org.opencv.core.Point;
|
||||||
import org.opencv.core.Scalar;
|
import org.opencv.core.Scalar;
|
||||||
import org.opencv.core.Size;
|
import org.opencv.core.Size;
|
||||||
import org.opencv.android.JavaCameraView;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView
|
|||||||
private MenuItem mItemPreviewZoom;
|
private MenuItem mItemPreviewZoom;
|
||||||
private MenuItem mItemPreviewPixelize;
|
private MenuItem mItemPreviewPixelize;
|
||||||
private MenuItem mItemPreviewPosterize;
|
private MenuItem mItemPreviewPosterize;
|
||||||
private JavaCameraView mOpenCvCameraView;
|
private CameraBridgeViewBase mOpenCvCameraView;
|
||||||
|
|
||||||
private Size mSize0;
|
private Size mSize0;
|
||||||
private Size mSizeRgba;
|
private Size mSizeRgba;
|
||||||
@ -106,7 +106,7 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView
|
|||||||
|
|
||||||
setContentView(R.layout.image_manipulations_surface_view);
|
setContentView(R.layout.image_manipulations_surface_view);
|
||||||
|
|
||||||
mOpenCvCameraView = (JavaCameraView)findViewById(R.id.image_manipulations_activity_surface_view);
|
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.image_manipulations_activity_surface_view);
|
||||||
mOpenCvCameraView.setCvCameraViewListener(this);
|
mOpenCvCameraView.setCvCameraViewListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,13 @@
|
|||||||
<org.opencv.android.JavaCameraView
|
<org.opencv.android.JavaCameraView
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:id="@+id/tutorial1_activity_surface_view" />
|
android:visibility="gone"
|
||||||
|
android:id="@+id/tutorial1_activity_java_surface_view" />
|
||||||
|
|
||||||
|
<org.opencv.android.NativeCameraView
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:id="@+id/tutorial1_activity_native_surface_view" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -4,19 +4,25 @@ import org.opencv.android.BaseLoaderCallback;
|
|||||||
import org.opencv.android.LoaderCallbackInterface;
|
import org.opencv.android.LoaderCallbackInterface;
|
||||||
import org.opencv.android.OpenCVLoader;
|
import org.opencv.android.OpenCVLoader;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||||
import org.opencv.android.JavaCameraView;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.SurfaceView;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class Sample1Java extends Activity implements CvCameraViewListener {
|
public class Sample1Java extends Activity implements CvCameraViewListener {
|
||||||
private static final String TAG = "OCVSample::Activity";
|
private static final String TAG = "OCVSample::Activity";
|
||||||
|
|
||||||
private JavaCameraView mOpenCvCameraView;
|
private CameraBridgeViewBase mOpenCvCameraView;
|
||||||
|
private boolean mIsJavaCamera = true;
|
||||||
|
private MenuItem mItemSwitchCamera = null;
|
||||||
|
|
||||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||||
@Override
|
@Override
|
||||||
@ -49,7 +55,13 @@ public class Sample1Java extends Activity implements CvCameraViewListener {
|
|||||||
|
|
||||||
setContentView(R.layout.tutorial1_surface_view);
|
setContentView(R.layout.tutorial1_surface_view);
|
||||||
|
|
||||||
mOpenCvCameraView = (JavaCameraView)findViewById(R.id.tutorial1_activity_surface_view);
|
if (mIsJavaCamera)
|
||||||
|
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_java_surface_view);
|
||||||
|
else
|
||||||
|
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_native_surface_view);
|
||||||
|
|
||||||
|
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
|
||||||
|
|
||||||
mOpenCvCameraView.setCvCameraViewListener(this);
|
mOpenCvCameraView.setCvCameraViewListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,6 +84,40 @@ public class Sample1Java extends Activity implements CvCameraViewListener {
|
|||||||
mOpenCvCameraView.disableView();
|
mOpenCvCameraView.disableView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
Log.i(TAG, "called onCreateOptionsMenu");
|
||||||
|
mItemSwitchCamera = menu.add("Switch camera");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
String toastMesage = new String();
|
||||||
|
Log.i(TAG, "called onOptionsItemSelected; selected item: " + item);
|
||||||
|
|
||||||
|
if (item == mItemSwitchCamera) {
|
||||||
|
mOpenCvCameraView.setVisibility(SurfaceView.GONE);
|
||||||
|
mIsJavaCamera = !mIsJavaCamera;
|
||||||
|
|
||||||
|
if (mIsJavaCamera) {
|
||||||
|
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_java_surface_view);
|
||||||
|
toastMesage = "Java Camera";
|
||||||
|
} else {
|
||||||
|
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_native_surface_view);
|
||||||
|
toastMesage = "Native Camera";
|
||||||
|
}
|
||||||
|
|
||||||
|
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
|
||||||
|
mOpenCvCameraView.setCvCameraViewListener(this);
|
||||||
|
mOpenCvCameraView.enableView();
|
||||||
|
Toast toast = Toast.makeText(this, toastMesage, Toast.LENGTH_LONG);
|
||||||
|
toast.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void onCameraViewStarted(int width, int height) {
|
public void onCameraViewStarted(int width, int height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import org.opencv.core.CvType;
|
|||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.core.Point;
|
import org.opencv.core.Point;
|
||||||
import org.opencv.core.Scalar;
|
import org.opencv.core.Scalar;
|
||||||
import org.opencv.android.NativeCameraView;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||||
import org.opencv.highgui.Highgui;
|
import org.opencv.highgui.Highgui;
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
@ -35,7 +35,7 @@ public class Sample2NativeCamera extends Activity implements CvCameraViewListene
|
|||||||
private Mat mRgba;
|
private Mat mRgba;
|
||||||
private Mat mIntermediateMat;
|
private Mat mIntermediateMat;
|
||||||
|
|
||||||
private NativeCameraView mOpenCvCameraView;
|
private CameraBridgeViewBase mOpenCvCameraView;
|
||||||
|
|
||||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||||
@Override
|
@Override
|
||||||
@ -68,7 +68,7 @@ public class Sample2NativeCamera extends Activity implements CvCameraViewListene
|
|||||||
|
|
||||||
setContentView(R.layout.tutorial2_surface_view);
|
setContentView(R.layout.tutorial2_surface_view);
|
||||||
|
|
||||||
mOpenCvCameraView = (NativeCameraView)findViewById(R.id.tutorial2_activity_surface_view);
|
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial2_activity_surface_view);
|
||||||
mOpenCvCameraView.setCvCameraViewListener(this);
|
mOpenCvCameraView.setCvCameraViewListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import org.opencv.android.LoaderCallbackInterface;
|
|||||||
import org.opencv.android.OpenCVLoader;
|
import org.opencv.android.OpenCVLoader;
|
||||||
import org.opencv.core.CvType;
|
import org.opencv.core.CvType;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.android.JavaCameraView;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ public class Sample3Native extends Activity implements CvCameraViewListener {
|
|||||||
|
|
||||||
private Mat mRgba;
|
private Mat mRgba;
|
||||||
private Mat mGrayMat;
|
private Mat mGrayMat;
|
||||||
private JavaCameraView mOpenCvCameraView;
|
private CameraBridgeViewBase mOpenCvCameraView;
|
||||||
|
|
||||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||||
@Override
|
@Override
|
||||||
@ -57,7 +57,7 @@ public class Sample3Native extends Activity implements CvCameraViewListener {
|
|||||||
|
|
||||||
setContentView(R.layout.tutorial3_surface_view);
|
setContentView(R.layout.tutorial3_surface_view);
|
||||||
|
|
||||||
mOpenCvCameraView = (JavaCameraView)findViewById(R.id.tutorial4_activity_surface_view);
|
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial4_activity_surface_view);
|
||||||
mOpenCvCameraView.setCvCameraViewListener(this);
|
mOpenCvCameraView.setCvCameraViewListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import org.opencv.android.LoaderCallbackInterface;
|
|||||||
import org.opencv.android.OpenCVLoader;
|
import org.opencv.android.OpenCVLoader;
|
||||||
import org.opencv.core.CvType;
|
import org.opencv.core.CvType;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.android.JavaCameraView;
|
import org.opencv.android.CameraBridgeViewBase;
|
||||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||||
import org.opencv.highgui.Highgui;
|
import org.opencv.highgui.Highgui;
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
@ -36,7 +36,7 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener {
|
|||||||
private MenuItem mItemPreviewCanny;
|
private MenuItem mItemPreviewCanny;
|
||||||
private MenuItem mItemPreviewFeatures;
|
private MenuItem mItemPreviewFeatures;
|
||||||
|
|
||||||
private JavaCameraView mOpenCvCameraView;
|
private CameraBridgeViewBase mOpenCvCameraView;
|
||||||
|
|
||||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||||
@Override
|
@Override
|
||||||
@ -73,7 +73,7 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener {
|
|||||||
|
|
||||||
setContentView(R.layout.tutorial4_surface_view);
|
setContentView(R.layout.tutorial4_surface_view);
|
||||||
|
|
||||||
mOpenCvCameraView = (JavaCameraView)findViewById(R.id.tutorial4_activity_surface_view);
|
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial4_activity_surface_view);
|
||||||
mOpenCvCameraView.setCvCameraViewListener(this);
|
mOpenCvCameraView.setCvCameraViewListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user