Base for new sample added.
authorAlexander Smorkalov <alexander.smorkalov@itseez.com>
Tue, 27 Nov 2012 08:47:16 +0000 (12:47 +0400)
committerAlexander Smorkalov <alexander.smorkalov@itseez.com>
Tue, 27 Nov 2012 14:06:43 +0000 (18:06 +0400)
samples/android/CMakeLists.txt
samples/android/tutorial-5-customcamera/.classpath [new file with mode: 0644]
samples/android/tutorial-5-customcamera/.project [new file with mode: 0644]
samples/android/tutorial-5-customcamera/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
samples/android/tutorial-5-customcamera/AndroidManifest.xml [new file with mode: 0644]
samples/android/tutorial-5-customcamera/CMakeLists.txt [new file with mode: 0644]
samples/android/tutorial-5-customcamera/res/drawable/icon.png [new file with mode: 0644]
samples/android/tutorial-5-customcamera/res/layout/tutorial5_surface_view.xml [new file with mode: 0644]
samples/android/tutorial-5-customcamera/res/values/strings.xml [new file with mode: 0644]
samples/android/tutorial-5-customcamera/src/org/opencv/samples/tutorial5/CustomJavaCameraView.java [new file with mode: 0644]
samples/android/tutorial-5-customcamera/src/org/opencv/samples/tutorial5/Sample5CustomCamera.java [new file with mode: 0644]

index bf96bdf..36495cc 100644 (file)
@@ -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 (file)
index 0000000..3f9691c
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+       <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="src" path="gen"/>
+       <classpathentry kind="output" path="bin/classes"/>
+</classpath>
diff --git a/samples/android/tutorial-5-customcamera/.project b/samples/android/tutorial-5-customcamera/.project
new file mode 100644 (file)
index 0000000..4d73807
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>OpenCV Tutorial 5 - Custom camera</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
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 (file)
index 0000000..b080d2d
--- /dev/null
@@ -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 (file)
index 0000000..7779cbe
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="org.opencv.samples.tutorial5"
+          android:versionCode="21"
+          android:versionName="2.1">
+
+    <application
+        android:label="@string/app_name"
+        android:icon="@drawable/icon"
+        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
+
+        <activity android:name="Sample5CustomCamera"
+                  android:label="@string/app_name"
+                  android:screenOrientation="landscape"
+                  android:configChanges="keyboardHidden|orientation">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+    <supports-screens android:resizeable="true"
+                      android:smallScreens="true"
+                      android:normalScreens="true"
+                      android:largeScreens="true"
+                      android:anyDensity="true" />
+
+    <uses-sdk android:minSdkVersion="8" />
+
+    <uses-permission android:name="android.permission.CAMERA"/>
+
+    <uses-feature android:name="android.hardware.camera" android:required="false"/>
+    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
+    <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
+    <uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>
+
+</manifest>
diff --git a/samples/android/tutorial-5-customcamera/CMakeLists.txt b/samples/android/tutorial-5-customcamera/CMakeLists.txt
new file mode 100644 (file)
index 0000000..92256bd
--- /dev/null
@@ -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 (file)
index 0000000..6304549
Binary files /dev/null and b/samples/android/tutorial-5-customcamera/res/drawable/icon.png differ
diff --git a/samples/android/tutorial-5-customcamera/res/layout/tutorial5_surface_view.xml b/samples/android/tutorial-5-customcamera/res/layout/tutorial5_surface_view.xml
new file mode 100644 (file)
index 0000000..2b858e4
--- /dev/null
@@ -0,0 +1,12 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
+
+    <org.opencv.samples.tutorial5.CustomJavaCameraView
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:visibility="gone"
+        android:id="@+id/tutorial5_activity_java_surface_view" />
+
+</LinearLayout>
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 (file)
index 0000000..d4bb35f
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">OCV T5 Custom Camera</string>
+</resources>
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 (file)
index 0000000..bd6ccc0
--- /dev/null
@@ -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 (file)
index 0000000..18a1ce6
--- /dev/null
@@ -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;
+    }
+}