From ea83d384c1eb9db2c3414e5b04d981075d0c3a24 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Fri, 30 Nov 2012 12:32:16 +0400 Subject: [PATCH] removing Android tutorial 0 since it has become irrelevant after moving to the new application framework --- samples/android/CMakeLists.txt | 1 - .../android/tutorial-0-androidcamera/.classpath | 8 - samples/android/tutorial-0-androidcamera/.project | 33 --- .../.settings/org.eclipse.jdt.core.prefs | 4 - .../tutorial-0-androidcamera/AndroidManifest.xml | 34 --- .../tutorial-0-androidcamera/CMakeLists.txt | 7 - .../tutorial-0-androidcamera/res/drawable/icon.png | Bin 1997 -> 0 bytes .../res/values/strings.xml | 4 - .../org/opencv/samples/tutorial0/Sample0Base.java | 53 ----- .../org/opencv/samples/tutorial0/Sample0View.java | 91 -------- .../opencv/samples/tutorial0/SampleViewBase.java | 231 --------------------- 11 files changed, 466 deletions(-) delete mode 100644 samples/android/tutorial-0-androidcamera/.classpath delete mode 100644 samples/android/tutorial-0-androidcamera/.project delete mode 100644 samples/android/tutorial-0-androidcamera/.settings/org.eclipse.jdt.core.prefs delete mode 100644 samples/android/tutorial-0-androidcamera/AndroidManifest.xml delete mode 100644 samples/android/tutorial-0-androidcamera/CMakeLists.txt delete mode 100644 samples/android/tutorial-0-androidcamera/res/drawable/icon.png delete mode 100644 samples/android/tutorial-0-androidcamera/res/values/strings.xml delete mode 100644 samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/Sample0Base.java delete mode 100644 samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/Sample0View.java delete mode 100644 samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java diff --git a/samples/android/CMakeLists.txt b/samples/android/CMakeLists.txt index bf96bdf..f52c669 100644 --- a/samples/android/CMakeLists.txt +++ b/samples/android/CMakeLists.txt @@ -11,7 +11,6 @@ add_subdirectory(face-detection) add_subdirectory(image-manipulations) add_subdirectory(color-blob-detection) -add_subdirectory(tutorial-0-androidcamera) add_subdirectory(tutorial-1-addopencv) add_subdirectory(tutorial-2-opencvcamera) add_subdirectory(tutorial-3-native) diff --git a/samples/android/tutorial-0-androidcamera/.classpath b/samples/android/tutorial-0-androidcamera/.classpath deleted file mode 100644 index d3bb07b..0000000 --- a/samples/android/tutorial-0-androidcamera/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/samples/android/tutorial-0-androidcamera/.project b/samples/android/tutorial-0-androidcamera/.project deleted file mode 100644 index 33b0065..0000000 --- a/samples/android/tutorial-0-androidcamera/.project +++ /dev/null @@ -1,33 +0,0 @@ - - - OpenCV Tutorial 0 - Android 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-0-androidcamera/.settings/org.eclipse.jdt.core.prefs b/samples/android/tutorial-0-androidcamera/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index b080d2d..0000000 --- a/samples/android/tutorial-0-androidcamera/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -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-0-androidcamera/AndroidManifest.xml b/samples/android/tutorial-0-androidcamera/AndroidManifest.xml deleted file mode 100644 index d703810..0000000 --- a/samples/android/tutorial-0-androidcamera/AndroidManifest.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/android/tutorial-0-androidcamera/CMakeLists.txt b/samples/android/tutorial-0-androidcamera/CMakeLists.txt deleted file mode 100644 index 5c5780a..0000000 --- a/samples/android/tutorial-0-androidcamera/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -set(sample example-tutorial-0-androidcamera) - -add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" SDK_TARGET 11 ${ANDROID_SDK_TARGET}) -if(TARGET ${sample}) - add_dependencies(opencv_android_examples ${sample}) -endif() - diff --git a/samples/android/tutorial-0-androidcamera/res/drawable/icon.png b/samples/android/tutorial-0-androidcamera/res/drawable/icon.png deleted file mode 100644 index 630454927b592eb585c21527c430fc739c7970a6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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 - - OCV T0 Android Camera - diff --git a/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/Sample0Base.java b/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/Sample0Base.java deleted file mode 100644 index 02a0a14..0000000 --- a/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/Sample0Base.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.opencv.samples.tutorial0; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.os.Bundle; -import android.util.Log; -import android.view.Window; - -public class Sample0Base extends Activity { - - private static final String TAG = "OCVSample::Activity"; - private Sample0View mView; - - public Sample0Base() { - Log.i(TAG, "Instantiated new " + this.getClass()); - } - - @Override - protected void onPause() { - Log.i(TAG, "called onPause"); - super.onPause(); - mView.releaseCamera(); - } - - @Override - protected void onResume() { - Log.i(TAG, "called onResume"); - super.onResume(); - if( !mView.openCamera() ) { - AlertDialog ad = new AlertDialog.Builder(this).create(); - ad.setCancelable(false); // This blocks the 'BACK' button - ad.setMessage("Fatal error: can't open camera!"); - ad.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - finish(); - } - }); - ad.show(); - } - } - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - Log.i(TAG, "called onCreate"); - super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_NO_TITLE); - mView = new Sample0View(this); - setContentView(mView); - } -} diff --git a/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/Sample0View.java b/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/Sample0View.java deleted file mode 100644 index dbe6947..0000000 --- a/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/Sample0View.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.opencv.samples.tutorial0; - -import android.content.Context; -import android.graphics.Bitmap; -import android.util.Log; - -class Sample0View extends SampleViewBase { - - private static final String TAG = "OCVSample::View"; - - public static final int VIEW_MODE_RGBA = 0; - public static final int VIEW_MODE_GRAY = 1; - - int mSize; - int[] mRGBA; - private Bitmap mBitmap; - private int mViewMode; - - public Sample0View(Context context) { - super(context); - mSize = 0; - mViewMode = VIEW_MODE_RGBA; - Log.i(TAG, "Instantiated new " + this.getClass()); - } - - @Override - protected Bitmap processFrame(byte[] data) { - int frameSize = getFrameWidth() * getFrameHeight(); - - int[] rgba = mRGBA; - - final int view_mode = mViewMode; - if (view_mode == VIEW_MODE_GRAY) { - for (int i = 0; i < frameSize; i++) { - int y = (0xff & ((int) data[i])); - rgba[i] = 0xff000000 + (y << 16) + (y << 8) + y; - } - } else if (view_mode == VIEW_MODE_RGBA) { - for (int i = 0; i < getFrameHeight(); i++) { - for (int j = 0; j < getFrameWidth(); j++) { - int index = i * getFrameWidth() + j; - int supply_index = frameSize + (i >> 1) * getFrameWidth() + (j & ~1); - int y = (0xff & ((int) data[index])); - int u = (0xff & ((int) data[supply_index + 0])); - int v = (0xff & ((int) data[supply_index + 1])); - y = y < 16 ? 16 : y; - - float y_conv = 1.164f * (y - 16); - int r = Math.round(y_conv + 1.596f * (v - 128)); - int g = Math.round(y_conv - 0.813f * (v - 128) - 0.391f * (u - 128)); - int b = Math.round(y_conv + 2.018f * (u - 128)); - - r = r < 0 ? 0 : (r > 255 ? 255 : r); - g = g < 0 ? 0 : (g > 255 ? 255 : g); - b = b < 0 ? 0 : (b > 255 ? 255 : b); - - rgba[i * getFrameWidth() + j] = 0xff000000 + (b << 16) + (g << 8) + r; - } - } - } - - mBitmap.setPixels(rgba, 0/* offset */, getFrameWidth() /* stride */, 0, 0, getFrameWidth(), getFrameHeight()); - return mBitmap; - } - - @Override - protected void onPreviewStarted(int previewWidth, int previewHeight) { - Log.i(TAG, "called onPreviewStarted("+previewWidth+", "+previewHeight+")"); - /* Create a bitmap that will be used through to calculate the image to */ - mBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Bitmap.Config.ARGB_8888); - mRGBA = new int[previewWidth * previewHeight]; - } - - @Override - protected void onPreviewStopped() { - Log.i(TAG, "called onPreviewStopped"); - if(mBitmap != null) { - mBitmap.recycle(); - mBitmap = null; - } - - if(mRGBA != null) { - mRGBA = null; - } - } - - public void setViewMode(int viewMode) { - Log.i(TAG, "called setViewMode("+viewMode+")"); - mViewMode = viewMode; - } -} \ No newline at end of file diff --git a/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java b/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java deleted file mode 100644 index 8db6fae..0000000 --- a/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.opencv.samples.tutorial0; - -import java.io.IOException; -import java.util.List; - -import android.annotation.TargetApi; -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.ImageFormat; -import android.graphics.SurfaceTexture; -import android.hardware.Camera; -import android.hardware.Camera.PreviewCallback; -import android.os.Build; -import android.util.Log; -import android.view.SurfaceHolder; -import android.view.SurfaceView; - -public abstract class SampleViewBase extends SurfaceView implements SurfaceHolder.Callback, Runnable { - private static final String TAG = "OCVSample::BaseView"; - - private Camera mCamera; - private SurfaceHolder mHolder; - private int mFrameWidth; - private int mFrameHeight; - private byte[] mFrame; - private volatile boolean mThreadRun; - private byte[] mBuffer; - private SurfaceTexture mSf; - - - public SampleViewBase(Context context) { - super(context); - mHolder = getHolder(); - mHolder.addCallback(this); - Log.i(TAG, "Instantiated new " + this.getClass()); - } - - public int getFrameWidth() { - return mFrameWidth; - } - - public int getFrameHeight() { - return mFrameHeight; - } - - @TargetApi(11) - public void setPreview() throws IOException { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - mSf = new SurfaceTexture(10); - mCamera.setPreviewTexture( mSf ); - } - else - mCamera.setPreviewDisplay(null); - } - - public boolean openCamera() { - Log.i(TAG, "Opening Camera"); - mCamera = null; - - try { - mCamera = Camera.open(); - } - catch (Exception e){ - Log.e(TAG, "Camera is not available (in use or does not exist): " + e.getLocalizedMessage()); - } - - if(mCamera == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { - for (int camIdx = 0; camIdx < Camera.getNumberOfCameras(); ++camIdx) { - try { - mCamera = Camera.open(camIdx); - } - catch (RuntimeException e) { - Log.e(TAG, "Camera #" + camIdx + "failed to open: " + e.getLocalizedMessage()); - } - } - } - - if(mCamera == null) { - Log.e(TAG, "Can't open any camera"); - return false; - } - - mCamera.setPreviewCallbackWithBuffer(new PreviewCallback() { - public void onPreviewFrame(byte[] data, Camera camera) { - synchronized (SampleViewBase.this) { - System.arraycopy(data, 0, mFrame, 0, data.length); - SampleViewBase.this.notify(); - } - camera.addCallbackBuffer(mBuffer); - } - }); - - return true; - } - - public void releaseCamera() { - Log.i(TAG, "Releasing Camera"); - mThreadRun = false; - synchronized (this) { - if (mCamera != null) { - mCamera.stopPreview(); - mCamera.release(); - mCamera = null; - } - } - onPreviewStopped(); - } - - public synchronized void setupCamera(int width, int height) { - if (mCamera != null) { - Log.i(TAG, "Setup Camera - " + width + "x" + height); - Camera.Parameters params = mCamera.getParameters(); - List sizes = params.getSupportedPreviewSizes(); - mFrameWidth = width; - mFrameHeight = height; - - // selecting optimal camera preview size - { - int minDiff = Integer.MAX_VALUE; - for (Camera.Size size : sizes) { - if (Math.abs(size.height - height) < minDiff) { - mFrameWidth = size.width; - mFrameHeight = size.height; - minDiff = Math.abs(size.height - height); - } - } - } - - params.setPreviewSize(getFrameWidth(), getFrameHeight()); - - List FocusModes = params.getSupportedFocusModes(); - if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) - { - params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); - } - - mCamera.setParameters(params); - - /* Now allocate the buffer */ - params = mCamera.getParameters(); - int size = params.getPreviewSize().width * params.getPreviewSize().height; - size = size * ImageFormat.getBitsPerPixel(params.getPreviewFormat()) / 8; - mBuffer = new byte[size]; - /* The buffer where the current frame will be copied */ - mFrame = new byte [size]; - mCamera.addCallbackBuffer(mBuffer); - - /* Notify that the preview is about to be started and deliver preview size */ - onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); - - try { - setPreview(); - } catch (IOException e) { - Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); - } - - /* Now we can start a preview */ - mCamera.startPreview(); - } - } - - public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) { - Log.i(TAG, "called surfaceChanged"); - // stop preview before making changes - try { - mCamera.stopPreview(); - } catch (Exception e){ - // ignore: tried to stop a non-existent preview - } - - // start preview with new settings - setupCamera(width, height); - } - - public void surfaceCreated(SurfaceHolder holder) { - Log.i(TAG, "called surfaceCreated"); - (new Thread(this)).start(); - } - - public void surfaceDestroyed(SurfaceHolder holder) { - Log.i(TAG, "called surfaceDestroyed"); - } - - /* The bitmap returned by this method shall be owned by the child and released in onPreviewStopped() */ - protected abstract Bitmap processFrame(byte[] data); - - /** - * This method is called when the preview process is being started. It is called before the first frame delivered and processFrame is called - * It is called with the width and height parameters of the preview process. It can be used to prepare the data needed during the frame processing. - * @param previewWidth - the width of the preview frames that will be delivered via processFrame - * @param previewHeight - the height of the preview frames that will be delivered via processFrame - */ - protected abstract void onPreviewStarted(int previewWidtd, int previewHeight); - - /** - * This method is called when preview is stopped. When this method is called the preview stopped and all the processing of frames already completed. - * If the Bitmap object returned via processFrame is cached - it is a good time to recycle it. - * Any other resources used during the preview can be released. - */ - protected abstract void onPreviewStopped(); - - public void run() { - mThreadRun = true; - Log.i(TAG, "Started processing thread"); - while (mThreadRun) { - Bitmap bmp = null; - - synchronized (this) { - try { - this.wait(); - if (!mThreadRun) - break; - bmp = processFrame(mFrame); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - if (bmp != null) { - Canvas canvas = mHolder.lockCanvas(); - if (canvas != null) { - canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR); - canvas.drawBitmap(bmp, (canvas.getWidth() - getFrameWidth()) / 2, (canvas.getHeight() - getFrameHeight()) / 2, null); - mHolder.unlockCanvasAndPost(canvas); - } - } - } - Log.i(TAG, "Finished processing thread"); - } -} \ No newline at end of file -- 2.7.4