From 24c920a33a25dcc65c7e174e181c73776bee57e3 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 27 Nov 2012 12:47:16 +0400 Subject: [PATCH] Base for new sample added. --- samples/android/CMakeLists.txt | 1 + .../tutorial-5-customcamera/.classpath | 8 ++ .../android/tutorial-5-customcamera/.project | 33 +++++ .../.settings/org.eclipse.jdt.core.prefs | 4 + .../AndroidManifest.xml | 38 ++++++ .../tutorial-5-customcamera/CMakeLists.txt | 7 + .../res/drawable/icon.png | Bin 0 -> 1997 bytes .../res/layout/tutorial5_surface_view.xml | 12 ++ .../res/values/strings.xml | 4 + .../tutorial5/CustomJavaCameraView.java | 19 +++ .../tutorial5/Sample5CustomCamera.java | 125 ++++++++++++++++++ 11 files changed, 251 insertions(+) create mode 100644 samples/android/tutorial-5-customcamera/.classpath create mode 100644 samples/android/tutorial-5-customcamera/.project create mode 100644 samples/android/tutorial-5-customcamera/.settings/org.eclipse.jdt.core.prefs create mode 100644 samples/android/tutorial-5-customcamera/AndroidManifest.xml create mode 100644 samples/android/tutorial-5-customcamera/CMakeLists.txt create mode 100644 samples/android/tutorial-5-customcamera/res/drawable/icon.png create mode 100644 samples/android/tutorial-5-customcamera/res/layout/tutorial5_surface_view.xml create mode 100644 samples/android/tutorial-5-customcamera/res/values/strings.xml create mode 100644 samples/android/tutorial-5-customcamera/src/org/opencv/samples/tutorial5/CustomJavaCameraView.java create mode 100644 samples/android/tutorial-5-customcamera/src/org/opencv/samples/tutorial5/Sample5CustomCamera.java diff --git a/samples/android/CMakeLists.txt b/samples/android/CMakeLists.txt index bf96bdf5a2..36495ccf52 100644 --- a/samples/android/CMakeLists.txt +++ b/samples/android/CMakeLists.txt @@ -16,6 +16,7 @@ add_subdirectory(tutorial-1-addopencv) add_subdirectory(tutorial-2-opencvcamera) add_subdirectory(tutorial-3-native) add_subdirectory(tutorial-4-mixed) +add_subdirectory(tutorial-5-customcamera) #hello-android sample if(HAVE_opencv_highgui) diff --git a/samples/android/tutorial-5-customcamera/.classpath b/samples/android/tutorial-5-customcamera/.classpath new file mode 100644 index 0000000000..3f9691c5dd --- /dev/null +++ b/samples/android/tutorial-5-customcamera/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/samples/android/tutorial-5-customcamera/.project b/samples/android/tutorial-5-customcamera/.project new file mode 100644 index 0000000000..4d7380723e --- /dev/null +++ b/samples/android/tutorial-5-customcamera/.project @@ -0,0 +1,33 @@ + + + OpenCV Tutorial 5 - Custom camera + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/samples/android/tutorial-5-customcamera/.settings/org.eclipse.jdt.core.prefs b/samples/android/tutorial-5-customcamera/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..b080d2ddc8 --- /dev/null +++ b/samples/android/tutorial-5-customcamera/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/samples/android/tutorial-5-customcamera/AndroidManifest.xml b/samples/android/tutorial-5-customcamera/AndroidManifest.xml new file mode 100644 index 0000000000..7779cbe66b --- /dev/null +++ b/samples/android/tutorial-5-customcamera/AndroidManifest.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/android/tutorial-5-customcamera/CMakeLists.txt b/samples/android/tutorial-5-customcamera/CMakeLists.txt new file mode 100644 index 0000000000..92256bdceb --- /dev/null +++ b/samples/android/tutorial-5-customcamera/CMakeLists.txt @@ -0,0 +1,7 @@ +set(sample example-tutorial-5-customcamera) + +add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET}) +if(TARGET ${sample}) + add_dependencies(opencv_android_examples ${sample}) +endif() + diff --git a/samples/android/tutorial-5-customcamera/res/drawable/icon.png b/samples/android/tutorial-5-customcamera/res/drawable/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..630454927b592eb585c21527c430fc739c7970a6 GIT binary patch literal 1997 zcmV;;2Qv7HP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L04^f{04^f|c%?sf00007bV*G`2iyk& z2s4Z(uWcvB1k+?B|HcZ5+p(*;Q^&-8AtzSnVCK7?)^Xiwf0*7z0ZN;t#z9i`sgtpqdV3hDNF*c2bKc!qcQaX zUny)Tz}^_l!dPca%!U9i64N>!i~1_h=?F58~*Mqs?aUag-wNp3eJ zaArHlobMV1PMO^yg*noOAUz|E0i{}8`nIiHOW|~F4mjoR_GH_vZVKN?bHNdXe;To> zxdyn_TnD>62p5lGlR~e9qrf7C+ui6sX@;J1@Mx>Yo=qMBRs~*)bDAoXUZYSHTab?f z_PACCXF@bcF}lW`X>mi~9D%@SGZ2{F%CTpbhLf>?v)%*vE3D~)z{*wz=t^t3pfEGA zffL(4AU5DX%yUkKoB_Jb(8oFW!NI-`j{z#&Z&^_sT-34vIXFYp`=GEPgYAu)4n9D4 z%K`*+8v7m2z|O!Kz|Xto?PB|!;VL`0G=ur`jDlQ$D=+i6dSt)j#Si?i#3rh3ZDkkx z+9TWVDcFEP;8fsZmts4LZyQ^=NS&&oMq^DBPd9*r!p~~YrdwMdQuxcK)CgcvlC7iQ z6m}XDL=_ke!d;S<2IvOy5aI>4B-sk!6i-qAqn6i#qR%}BH;aqaE~#zv6|u2ViZHn? z1hW8E8rkz`nyn$2WU0dhK4^p<)W{{jH|2^S^#FZ&jV&V)7;HC58VOgls*{S?bCuB! zgJG~P)&TrE+Oa9jPq^~G`MQI^ISDar1?}7f7D?&qi-Zc{Oivqep0%xlm22B7?$lt? zRDoZ$&ZSsjO2nE0ft%CR$aVrKp5WRX7^zue>Cw3+QGx=M@MFBYs{CEWmLZ zN*9hpz)s*B96QRjjj`Qi_;Vb>Z73h0DK9}$-axr}l%1BFSp9)x9Ky;`(^n%*$`F!V zkY*oPaAK+6&unXUeSit`5c;F3iU&9)kOVILi%-C3#za9jc>jUr;Wvs~#jZ#FaZ!2fi34Sb1N@BsFCj&@J zs;eb(o@Ffe=D?d6qPKGdXKQjn9~5j94Pu>ge`)`61V~3frX{l7>dTEi%6<8;N9K*(u}%^bWomltk*Vp@k|^lo)yA?qH}(jBlCHBo51XA|gNf(* zoeh<>k{r9Y4)pw$!k7FX&+PyB(?mq~(*^;K7{UQF&X#s!ILS zHX&7zhmyZ|_z=x$C7sRWW=r7+&daHU&gPWWQt)uC*X>tEFZ6J;H6WaAcCCQRo2VjP z>v8^kmJJ*U_eqdHY-p9+xixW&Umgf^mpLS>_nMj zvaJlD2pv8o7#@|SuT=D$XZ)5=GJyZFvEPhNoO#NE^Nc>q2{?8F#Z+({^MQk9zw9zH z=)VjA4HzfT(Fq(eDSwVGl!7_^3!$70OgHG7MYIxpx7Q{~Cgnag|7WoceAizs@IKwlGBBq*Ioi0qby4ylKkgqvR5BcLR&Vy39?8 + + + + diff --git a/samples/android/tutorial-5-customcamera/res/values/strings.xml b/samples/android/tutorial-5-customcamera/res/values/strings.xml new file mode 100644 index 0000000000..d4bb35f547 --- /dev/null +++ b/samples/android/tutorial-5-customcamera/res/values/strings.xml @@ -0,0 +1,4 @@ + + + OCV T5 Custom Camera + diff --git a/samples/android/tutorial-5-customcamera/src/org/opencv/samples/tutorial5/CustomJavaCameraView.java b/samples/android/tutorial-5-customcamera/src/org/opencv/samples/tutorial5/CustomJavaCameraView.java new file mode 100644 index 0000000000..bd6ccc04be --- /dev/null +++ b/samples/android/tutorial-5-customcamera/src/org/opencv/samples/tutorial5/CustomJavaCameraView.java @@ -0,0 +1,19 @@ +package org.opencv.samples.tutorial5; + +import org.opencv.android.JavaCameraView; + +import android.content.Context; +import android.util.AttributeSet; + +public class CustomJavaCameraView extends JavaCameraView { + + public CustomJavaCameraView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected boolean connectCamera(int width, int height) { + boolean result = super.connectCamera(width, height); + return result; + } +} diff --git a/samples/android/tutorial-5-customcamera/src/org/opencv/samples/tutorial5/Sample5CustomCamera.java b/samples/android/tutorial-5-customcamera/src/org/opencv/samples/tutorial5/Sample5CustomCamera.java new file mode 100644 index 0000000000..18a1ce6f3e --- /dev/null +++ b/samples/android/tutorial-5-customcamera/src/org/opencv/samples/tutorial5/Sample5CustomCamera.java @@ -0,0 +1,125 @@ +package org.opencv.samples.tutorial5; + +import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.LoaderCallbackInterface; +import org.opencv.android.OpenCVLoader; +import org.opencv.core.Mat; +import org.opencv.android.CameraBridgeViewBase; +import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; + +import android.app.Activity; +import android.os.Bundle; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.SurfaceView; +import android.view.WindowManager; +import android.widget.Toast; + +public class Sample5CustomCamera extends Activity implements CvCameraViewListener { + private static final String TAG = "OCVSample::Activity"; + + private CameraBridgeViewBase mOpenCvCameraView; + private boolean mIsJavaCamera = true; + private MenuItem mItemSwitchCamera = null; + + private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { + @Override + public void onManagerConnected(int status) { + switch (status) { + case LoaderCallbackInterface.SUCCESS: + { + Log.i(TAG, "OpenCV loaded successfully"); + mOpenCvCameraView.enableView(); + } break; + default: + { + super.onManagerConnected(status); + } break; + } + } + }; + + public Sample5CustomCamera() { + Log.i(TAG, "Instantiated new " + this.getClass()); + } + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + Log.i(TAG, "called onCreate"); + super.onCreate(savedInstanceState); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + + setContentView(R.layout.tutorial5_surface_view); + + if (mIsJavaCamera) + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial5_activity_java_surface_view); + + mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); + + mOpenCvCameraView.setCvCameraViewListener(this); + } + + @Override + public void onPause() + { + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); + super.onPause(); + } + + @Override + public void onResume() + { + super.onResume(); + OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback); + } + + public void onDestroy() { + super.onDestroy(); + if (mOpenCvCameraView != null) + 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.tutorial5_activity_java_surface_view); + toastMesage = "Java 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 onCameraViewStopped() { + } + + public Mat onCameraFrame(Mat inputFrame) { + return inputFrame; + } +}