From 95b7f5c46cf935581e32d56b408324869378b8ca Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Wed, 7 Nov 2012 13:27:33 +0400 Subject: [PATCH 1/8] Face Detection sample namespace replaced on org.opencv.facedetect for consistency with Google Play. --- .../face-detection/AndroidManifest.xml | 2 +- .../jni/DetectionBasedTracker_jni.cpp | 50 +++++++++---------- .../jni/DetectionBasedTracker_jni.h | 12 ++--- .../DetectionBasedTracker.java | 2 +- .../{fd => facedetect}/FdActivity.java | 2 +- .../samples/{fd => facedetect}/FpsMeter.java | 2 +- 6 files changed, 35 insertions(+), 35 deletions(-) rename samples/android/face-detection/src/org/opencv/samples/{fd => facedetect}/DetectionBasedTracker.java (96%) rename samples/android/face-detection/src/org/opencv/samples/{fd => facedetect}/FdActivity.java (99%) rename samples/android/face-detection/src/org/opencv/samples/{fd => facedetect}/FpsMeter.java (97%) diff --git a/samples/android/face-detection/AndroidManifest.xml b/samples/android/face-detection/AndroidManifest.xml index eaa90dfd08..a52dc660eb 100644 --- a/samples/android/face-detection/AndroidManifest.xml +++ b/samples/android/face-detection/AndroidManifest.xml @@ -1,6 +1,6 @@ diff --git a/samples/android/face-detection/jni/DetectionBasedTracker_jni.cpp b/samples/android/face-detection/jni/DetectionBasedTracker_jni.cpp index 33ee8e7a52..417fea5226 100644 --- a/samples/android/face-detection/jni/DetectionBasedTracker_jni.cpp +++ b/samples/android/face-detection/jni/DetectionBasedTracker_jni.cpp @@ -65,15 +65,15 @@ struct DetectorAgregator } }; -JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject +JNIEXPORT jlong JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject (JNIEnv * jenv, jclass, jstring jFileName, jint faceSize) { - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject enter"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject enter"); const char* jnamestr = jenv->GetStringUTFChars(jFileName, NULL); string stdFileName(jnamestr); jlong result = 0; - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject"); try { @@ -98,18 +98,18 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeC { LOGD("nativeCreateObject catched unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); - jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject(...)}"); + jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject(...)}"); return 0; } - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject exit"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject exit"); return result; } -JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject +JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDestroyObject (JNIEnv * jenv, jclass, jlong thiz) { - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDestroyObject"); try { @@ -131,15 +131,15 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe { LOGD("nativeDestroyObject catched unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); - jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject(...)}"); + jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDestroyObject(...)}"); } - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject exit"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDestroyObject exit"); } -JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart +JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStart (JNIEnv * jenv, jclass, jlong thiz) { - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStart"); try { @@ -157,15 +157,15 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt { LOGD("nativeStart catched unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); - jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart(...)}"); + jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStart(...)}"); } - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart exit"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStart exit"); } -JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop +JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStop (JNIEnv * jenv, jclass, jlong thiz) { - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStop"); try { @@ -183,15 +183,15 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt { LOGD("nativeStop catched unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); - jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop(...)}"); + jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStop(...)}"); } - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop exit"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStop exit"); } -JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize +JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeSetFaceSize (JNIEnv * jenv, jclass, jlong thiz, jint faceSize) { - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize -- BEGIN"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeSetFaceSize -- BEGIN"); try { @@ -213,16 +213,16 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSe { LOGD("nativeSetFaceSize catched unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); - jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize(...)}"); + jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeSetFaceSize(...)}"); } - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize -- END"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeSetFaceSize -- END"); } -JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect +JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDetect (JNIEnv * jenv, jclass, jlong thiz, jlong imageGray, jlong faces) { - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDetect"); try { @@ -243,7 +243,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe { LOGD("nativeDetect catched unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); - jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect(...)}"); + jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDetect(...)}"); } - LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect END"); + LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDetect END"); } diff --git a/samples/android/face-detection/jni/DetectionBasedTracker_jni.h b/samples/android/face-detection/jni/DetectionBasedTracker_jni.h index 7ae94c3dd7..7e0541d810 100644 --- a/samples/android/face-detection/jni/DetectionBasedTracker_jni.h +++ b/samples/android/face-detection/jni/DetectionBasedTracker_jni.h @@ -12,7 +12,7 @@ extern "C" { * Method: nativeCreateObject * Signature: (Ljava/lang/String;F)J */ -JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject +JNIEXPORT jlong JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject (JNIEnv *, jclass, jstring, jint); /* @@ -20,7 +20,7 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeC * Method: nativeDestroyObject * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject +JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDestroyObject (JNIEnv *, jclass, jlong); /* @@ -28,7 +28,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe * Method: nativeStart * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart +JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStart (JNIEnv *, jclass, jlong); /* @@ -36,7 +36,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt * Method: nativeStop * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop +JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStop (JNIEnv *, jclass, jlong); /* @@ -44,7 +44,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt * Method: nativeSetFaceSize * Signature: (JI)V */ - JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize + JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeSetFaceSize (JNIEnv *, jclass, jlong, jint); /* @@ -52,7 +52,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt * Method: nativeDetect * Signature: (JJJ)V */ -JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect +JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDetect (JNIEnv *, jclass, jlong, jlong, jlong); #ifdef __cplusplus diff --git a/samples/android/face-detection/src/org/opencv/samples/fd/DetectionBasedTracker.java b/samples/android/face-detection/src/org/opencv/samples/facedetect/DetectionBasedTracker.java similarity index 96% rename from samples/android/face-detection/src/org/opencv/samples/fd/DetectionBasedTracker.java rename to samples/android/face-detection/src/org/opencv/samples/facedetect/DetectionBasedTracker.java index 9e46005438..6179f1bdc1 100644 --- a/samples/android/face-detection/src/org/opencv/samples/fd/DetectionBasedTracker.java +++ b/samples/android/face-detection/src/org/opencv/samples/facedetect/DetectionBasedTracker.java @@ -1,4 +1,4 @@ -package org.opencv.samples.fd; +package org.opencv.samples.facedetect; import org.opencv.core.Mat; import org.opencv.core.MatOfRect; diff --git a/samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java b/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java similarity index 99% rename from samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java rename to samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java index 9470a8fd1f..2b949629cc 100644 --- a/samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java +++ b/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java @@ -1,4 +1,4 @@ -package org.opencv.samples.fd; +package org.opencv.samples.facedetect; import java.io.File; import java.io.FileOutputStream; diff --git a/samples/android/face-detection/src/org/opencv/samples/fd/FpsMeter.java b/samples/android/face-detection/src/org/opencv/samples/facedetect/FpsMeter.java similarity index 97% rename from samples/android/face-detection/src/org/opencv/samples/fd/FpsMeter.java rename to samples/android/face-detection/src/org/opencv/samples/facedetect/FpsMeter.java index 2c8f3bc7b7..2438bf89ac 100644 --- a/samples/android/face-detection/src/org/opencv/samples/fd/FpsMeter.java +++ b/samples/android/face-detection/src/org/opencv/samples/facedetect/FpsMeter.java @@ -1,4 +1,4 @@ -package org.opencv.samples.fd; +package org.opencv.samples.facedetect; import java.text.DecimalFormat; From 7ef378b230eaa3363b1af94b42cbe8be7065370c Mon Sep 17 00:00:00 2001 From: mikle Date: Fri, 2 Nov 2012 18:27:26 +0600 Subject: [PATCH 2/8] Android tutorial updated. HelloWorld sample ported on new framework. --- .../dev_with_OCV_on_Android.rst | 257 +++++------------- 1 file changed, 75 insertions(+), 182 deletions(-) diff --git a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst index f7f0c4718c..52f7393616 100644 --- a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst +++ b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst @@ -270,105 +270,6 @@ It will be capable of accessing camera output, processing it and displaying the #. Set name, target, package and minSDKVersion accordingly. -#. Create a new class (*File -> New -> Class*). Name it for example: *HelloOpenCVView*. - - .. image:: images/dev_OCV_new_class.png - :alt: Add a new class. - :align: center - - * It should extend *SurfaceView* class. - * It also should implement *SurfaceHolder.Callback*, *Runnable*. - -#. Edit *HelloOpenCVView* class. - - * Add an *import* line for *android.content.context*. - - * Modify autogenerated stubs: *HelloOpenCVView*, *surfaceCreated*, *surfaceDestroyed* and *surfaceChanged*. - - .. code-block:: java - :linenos: - - package com.hello.opencv.test; - - import android.content.Context; - - public class HelloOpenCVView extends SurfaceView implements Callback, Runnable { - - public HelloOpenCVView(Context context) { - super(context); - getHolder().addCallback(this); - } - - public void surfaceCreated(SurfaceHolder holder) { - (new Thread(this)).start(); - } - - public void surfaceDestroyed(SurfaceHolder holder) { - cameraRelease(); - } - - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - cameraSetup(width, height); - } - - //... - - * Add *cameraOpen*, *cameraRelease* and *cameraSetup* voids as shown below. - - * Also, don't forget to add the public void *run()* as follows: - - .. code-block:: java - :linenos: - - public void run() { - // TODO: loop { getFrame(), processFrame(), drawFrame() } - } - - public boolean cameraOpen() { - return false; //TODO: open camera - } - - private void cameraRelease() { - // TODO release camera - } - - private void cameraSetup(int width, int height) { - // TODO setup camera - } - -#. Create a new *Activity* (*New -> Other -> Android -> Android Activity*) and name it, for example: *HelloOpenCVActivity*. For this activity define *onCreate*, *onResume* and *onPause* voids. - - .. code-block:: java - :linenos: - - public void onCreate (Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mView = new HelloOpenCVView(this); - setContentView (mView); - } - - protected void onPause() { - super.onPause(); - mView.cameraRelease(); - } - - protected void onResume() { - super.onResume(); - if( !mView.cameraOpen() ) { - // MessageBox and exit app - 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("OK", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - finish(); - } - }); - ad.show(); - } - } - #. Add the following permissions to the AndroidManifest.xml file: .. code-block:: xml @@ -386,98 +287,90 @@ It will be capable of accessing camera output, processing it and displaying the :alt: Reference OpenCV library. :align: center -#. We now need some code to handle the camera. Update the *HelloOpenCVView* class as follows: +#. Create new view layout for your application, lets name it hello_opencv.xml, and add the following to it: + + .. code-block:: xml + :linenos: + + + + + + + +#. Remove default auto generated layout, if exists. + +#. Create a new *Activity* (*New -> Other -> Android -> Android Activity*) and name it, for example: *HelloOpenCVActivity*. Add *CvCameraViewListener* interface to *implementes* section of *HelloOpenCVActivity* class. Add the following code to activity implementation: .. code-block:: java :linenos: - private VideoCapture mCamera; + public class Sample1Java extends Activity implements CvCameraViewListener { + + private CameraBridgeViewBase mOpenCvCameraView; - public boolean cameraOpen() { - synchronized (this) { - cameraRelease(); - mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID); - if (!mCamera.isOpened()) { - mCamera.release(); - mCamera = null; - Log.e("HelloOpenCVView", "Failed to open native camera"); - return false; - } - } - return true; - } + 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); + } + } + }; - public void cameraRelease() { - synchronized(this) { - if (mCamera != null) { - mCamera.release(); - mCamera = null; - } - } - } + /** 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); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + setContentView(R.layout.hello_opencv); + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.java_surface_view); + mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); + mOpenCvCameraView.setCvCameraViewListener(this); + } - private void cameraSetup(int width, int height) { - synchronized (this) { - if (mCamera != null && mCamera.isOpened()) { - List sizes = mCamera.getSupportedPreviewSizes(); - int mFrameWidth = width; - int mFrameHeight = height; - { // selecting optimal camera preview size - double minDiff = Double.MAX_VALUE; - for (Size size : sizes) { - if (Math.abs(size.height - height) < minDiff) { - mFrameWidth = (int) size.width; - mFrameHeight = (int) size.height; - minDiff = Math.abs(size.height - height); - } - } - } - mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth); - mCamera.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight); - } - } - } + @Override + public void onPause() + { + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); + super.onPause(); + } -#. The last step would be to update the *run()* void in *HelloOpenCVView* class as follows: + @Override + public void onResume() + { + super.onResume(); + OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback); + } - .. code-block:: java - :linenos: + public void onDestroy() { + super.onDestroy(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); + } - public void run() { - while (true) { - Bitmap bmp = null; - synchronized (this) { - if (mCamera == null) - break; - if (!mCamera.grab()) - break; + public void onCameraViewStarted(int width, int height) { + } - bmp = processFrame(mCamera); - } - if (bmp != null) { - Canvas canvas = getHolder().lockCanvas(); - if (canvas != null) { - canvas.drawBitmap(bmp, (canvas.getWidth() - bmp.getWidth()) / 2, - (canvas.getHeight() - bmp.getHeight()) / 2, null); - getHolder().unlockCanvasAndPost(canvas); + public void onCameraViewStopped() { + } - } - bmp.recycle(); - } - } - } - - protected Bitmap processFrame(VideoCapture capture) { - Mat mRgba = new Mat(); - capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA); - //process mRgba - Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888); - try { - Utils.matToBitmap(mRgba, bmp); - } catch(Exception e) { - Log.e("processFrame", "Utils.matToBitmap() throws an exception: " + e.getMessage()); - bmp.recycle(); - bmp = null; - } - return bmp; - } + public Mat onCameraFrame(Mat inputFrame) { + return inputFrame; + } + } From baef62b4d2c8942ce6fe8a3a62113bc4ce14b8eb Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 9 Nov 2012 11:46:14 +0400 Subject: [PATCH 3/8] Java test fix. Eclipse test execution fix. --- .../src/org/opencv/test/OpenCVTestCase.java | 2 + .../src/org/opencv/test/OpenCVTestRunner.java | 24 +++--- .../features2d/FASTFeatureDetectorTest.java | 9 +- .../org/opencv/test/highgui/HighguiTest.java | 6 +- .../opencv/test/highgui/VideoCaptureTest.java | 83 ++++++++++++++----- 5 files changed, 87 insertions(+), 37 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java index 102adf1958..f8f3c6f896 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -28,6 +28,8 @@ public class OpenCVTestCase extends TestCase { //change to 'true' to unblock fail on fail("Not yet implemented") public static final boolean passNYI = true; + protected static boolean isEnabled = true; + protected static final int matSize = 10; protected static final double EPS = 0.001; protected static final double weakEPS = 0.5; diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java index 3c416c5104..f77801211b 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java @@ -2,9 +2,9 @@ package org.opencv.test; import java.io.File; import java.io.IOException; -import java.util.Iterator; +//import java.util.Iterator; -import junit.framework.TestCase; +//import junit.framework.TestCase; import junit.framework.Assert; import org.opencv.android.Utils; @@ -72,15 +72,17 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { //List testCases = androidTestRunner.getTestCases(); //Collections.shuffle(testCases); //shuffle the tests order - if(OpenCVTestCase.passNYI) { - // turn off problematic camera tests - Iterator it = androidTestRunner.getTestCases().iterator(); - while (it.hasNext()) { - String name = it.next().toString(); - if (name.contains("VideoCaptureTest")) - it.remove(); - } - } + // Note: VideoCapture tests turned off by flag field in VideoCaptureTest class + +// if(OpenCVTestCase.passNYI) { +// // turn off problematic camera tests +// Iterator it = androidTestRunner.getTestCases().iterator(); +// while (it.hasNext()) { +// String name = it.next().toString(); +// if (name.contains("VideoCaptureTest")) +// it.remove(); +// } +// } super.onStart(); diff --git a/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java index 35ffd6477e..4e068e1ac6 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java @@ -13,6 +13,8 @@ import org.opencv.features2d.KeyPoint; import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestRunner; +import android.util.Log; + public class FASTFeatureDetectorTest extends OpenCVTestCase { FeatureDetector detector; @@ -127,9 +129,9 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { detector.write(filename); - String truth = "\n\nFeature2D.FAST\n1\n10\n\n"; + String truth = "\n\nFeature2D.FAST\n1\n10\n2\n\n"; String data = readFile(filename); - + Log.d("qqq", "\"" + data + "\""); assertEquals(truth, data); } @@ -138,9 +140,10 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { detector.write(filename); - String truth = "%YAML:1.0\nname: \"Feature2D.FAST\"\nnonmaxSuppression: 1\nthreshold: 10\n"; + String truth = "%YAML:1.0\nname: \"Feature2D.FAST\"\nnonmaxSuppression: 1\nthreshold: 10\ntype: 2\n"; String data = readFile(filename); + Log.d("qqq", "\"" + data + "\""); assertEquals(truth, data); } } diff --git a/modules/java/android_test/src/org/opencv/test/highgui/HighguiTest.java b/modules/java/android_test/src/org/opencv/test/highgui/HighguiTest.java index 9f78727713..b8e7c3b8b2 100644 --- a/modules/java/android_test/src/org/opencv/test/highgui/HighguiTest.java +++ b/modules/java/android_test/src/org/opencv/test/highgui/HighguiTest.java @@ -22,10 +22,10 @@ public class HighguiTest extends OpenCVTestCase { public void testImencodeStringMatListOfByteListOfInteger() { MatOfInt params40 = new MatOfInt(Highgui.IMWRITE_JPEG_QUALITY, 40); MatOfInt params90 = new MatOfInt(Highgui.IMWRITE_JPEG_QUALITY, 90); - /* or + /* or MatOfInt params = new MatOfInt(); - params.fromArray(Highgui.IMWRITE_JPEG_QUALITY, 40); - */ + params.fromArray(Highgui.IMWRITE_JPEG_QUALITY, 40); + */ MatOfByte buff40 = new MatOfByte(); MatOfByte buff90 = new MatOfByte(); diff --git a/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java b/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java index c6901c5e4d..ce210714c1 100644 --- a/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java +++ b/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java @@ -19,13 +19,17 @@ public class VideoCaptureTest extends OpenCVTestCase { super.setUp(); capture = null; + isEnabled = false; isSucceed = false; isOpened = false; } public void testGet() { - try - { + if (!isEnabled) { + fail("Not yet implemented"); + } + + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); double frameWidth = capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH); assertTrue(0 != frameWidth); @@ -35,8 +39,11 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testGetSupportedPreviewSizes() { - try - { + if (!isEnabled) { + fail("Not yet implemented"); + } + + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); List sizes = capture.getSupportedPreviewSizes(); assertNotNull(sizes); @@ -47,12 +54,20 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testGrab() { + if (!isEnabled) { + fail("Not yet implemented"); + } + capture = new VideoCapture(); isSucceed = capture.grab(); assertFalse(isSucceed); } public void testGrabFromRealCamera() { + if (!isEnabled) { + fail("Not yet implemented"); + } + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); isSucceed = capture.grab(); @@ -63,13 +78,20 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testIsOpened() { + if (!isEnabled) { + fail("Not yet implemented"); + } + capture = new VideoCapture(); assertFalse(capture.isOpened()); } public void testIsOpenedRealCamera() { - try - { + if (!isEnabled) { + fail("Not yet implemented"); + } + + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); isOpened = capture.isOpened(); assertTrue(isOpened); @@ -79,8 +101,11 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testOpen() { - try - { + if (!isEnabled) { + fail("Not yet implemented"); + } + + try { capture = new VideoCapture(); capture.open(Highgui.CV_CAP_ANDROID); isOpened = capture.isOpened(); @@ -91,8 +116,11 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRead() { - try - { + if (!isEnabled) { + fail("Not yet implemented"); + } + + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); isSucceed = capture.read(dst); assertTrue(isSucceed); @@ -104,8 +132,11 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRelease() { - try - { + if (!isEnabled) { + fail("Not yet implemented"); + } + + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.release(); assertFalse(capture.isOpened()); @@ -116,8 +147,11 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRetrieveMat() { - try - { + if (!isEnabled) { + fail("Not yet implemented"); + } + + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.grab(); isSucceed = capture.retrieve(dst); @@ -130,8 +164,11 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRetrieveMatInt() { - try - { + if (!isEnabled) { + fail("Not yet implemented"); + } + + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.grab(); isSucceed = capture.retrieve(dst, Highgui.CV_CAP_ANDROID_GREY_FRAME); @@ -144,8 +181,11 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testSet() { - try - { + if (!isEnabled) { + fail("Not yet implemented"); + } + + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 640); capture.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 480); @@ -165,8 +205,11 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testVideoCaptureInt() { - try - { + if (!isEnabled) { + fail("Not yet implemented"); + } + + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); assertNotNull(capture); assertTrue(capture.isOpened()); From dda2eb0f76535a56a719fc4b6cfac5b9bba62951 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 9 Nov 2012 12:16:48 +0400 Subject: [PATCH 4/8] Libinfo build fix; Libinfo revision formating fix; HW dependent VersionCode for Manager implemented. --- CMakeLists.txt | 2 +- android/libinfo/info.c | 2 +- android/service/engine/AndroidManifest.xml | 2 +- android/service/engine/CMakeLists.txt | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0502fb8995..8707e0155d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -467,7 +467,7 @@ if(BUILD_ANDROID_PACKAGE) add_subdirectory(android/package) endif() -if (ANDROID AND NOT BUILD_ANDROID_SERVICE AND NOT BUILD_ANDROID_PACKAGE AND NOT BUILD_CAMERA_WRAPER) +if (ANDROID) add_subdirectory(android/libinfo) endif() diff --git a/android/libinfo/info.c b/android/libinfo/info.c index f1e5bf01ed..f0c2dd6a28 100644 --- a/android/libinfo/info.c +++ b/android/libinfo/info.c @@ -7,7 +7,7 @@ const char* GetLibraryList(void); JNIEXPORT jstring JNICALL Java_org_opencv_android_StaticHelper_getLibraryList(JNIEnv *, jclass); #define PACKAGE_NAME "org.opencv.lib_v" CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) "_" ANDROID_PACKAGE_PLATFORM -#define PACKAGE_REVISION CVAUX_STR(CV_SUBMINOR_VERSION) CVAUX_STR(ANDROID_PACKAGE_RELEASE) +#define PACKAGE_REVISION CVAUX_STR(CV_SUBMINOR_VERSION) "." CVAUX_STR(ANDROID_PACKAGE_RELEASE) const char* GetPackageName(void) { diff --git a/android/service/engine/AndroidManifest.xml b/android/service/engine/AndroidManifest.xml index b1d6f691c3..55cddcd8cb 100644 --- a/android/service/engine/AndroidManifest.xml +++ b/android/service/engine/AndroidManifest.xml @@ -1,7 +1,7 @@ diff --git a/android/service/engine/CMakeLists.txt b/android/service/engine/CMakeLists.txt index 529aef9bd5..b0d8425ca4 100644 --- a/android/service/engine/CMakeLists.txt +++ b/android/service/engine/CMakeLists.txt @@ -4,6 +4,24 @@ set(JNI_LIB_NAME ${engine} ${engine}_jni) unset(__android_project_chain CACHE) add_android_project(opencv_engine "${CMAKE_CURRENT_SOURCE_DIR}" SDK_TARGET 8 ${ANDROID_SDK_TARGET} IGNORE_JAVA ON) +set(ANDROID_PLATFORM_VERSION_CODE "0") + +if(ARMEABI_V7A) + set(ANDROID_PLATFORM_VERSION_CODE "2") + elseif(ARMEABI_V6) + set(ANDROID_PLATFORM_VERSION_CODE "1") + elseif(ARMEABI) + set(ANDROID_PLATFORM_VERSION_CODE "1") + elseif(X86) + set(ANDROID_PLATFORM_VERSION_CODE "3") + elseif(MIPS) + set(ANDROID_PLATFORM_VERSION_CODE "4") + else() + message(WARNING "Can not automatically determine the value for ANDROID_PLATFORM_VERSION_CODE") + endif() + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/android/service/engine/.build/${ANDROID_MANIFEST_FILE}" @ONLY) + link_directories("${ANDROID_SOURCE_TREE}/out/target/product/generic/system/lib" "${ANDROID_SOURCE_TREE}/out/target/product/${ANDROID_PRODUCT}/system/lib" "${ANDROID_SOURCE_TREE}/bin/${ANDROID_ARCH_NAME}") # -D__SUPPORT_ARMEABI_FEATURES key is also available From e06c5b6fd5c9c186176263b2def0f71c18af2cfa Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 12 Nov 2012 17:47:20 +0400 Subject: [PATCH 5/8] Code review comments applied. --- .../src/org/opencv/test/OpenCVTestCase.java | 2 +- .../src/org/opencv/test/OpenCVTestRunner.java | 14 ---------- .../opencv/test/highgui/VideoCaptureTest.java | 28 +++++++++---------- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java index f8f3c6f896..6acf0b34db 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -28,7 +28,7 @@ public class OpenCVTestCase extends TestCase { //change to 'true' to unblock fail on fail("Not yet implemented") public static final boolean passNYI = true; - protected static boolean isEnabled = true; + protected static boolean isTestCaseEnabled = true; protected static final int matSize = 10; protected static final double EPS = 0.001; diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java index f77801211b..3bd0be249a 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java @@ -2,9 +2,6 @@ package org.opencv.test; import java.io.File; import java.io.IOException; -//import java.util.Iterator; - -//import junit.framework.TestCase; import junit.framework.Assert; import org.opencv.android.Utils; @@ -74,17 +71,6 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { // Note: VideoCapture tests turned off by flag field in VideoCaptureTest class -// if(OpenCVTestCase.passNYI) { -// // turn off problematic camera tests -// Iterator it = androidTestRunner.getTestCases().iterator(); -// while (it.hasNext()) { -// String name = it.next().toString(); -// if (name.contains("VideoCaptureTest")) -// it.remove(); -// } -// } - - super.onStart(); } diff --git a/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java b/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java index ce210714c1..903768f7bf 100644 --- a/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java +++ b/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java @@ -19,13 +19,13 @@ public class VideoCaptureTest extends OpenCVTestCase { super.setUp(); capture = null; - isEnabled = false; + isTestCaseEnabled = false; isSucceed = false; isOpened = false; } public void testGet() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -39,7 +39,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testGetSupportedPreviewSizes() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -54,7 +54,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testGrab() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -64,7 +64,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testGrabFromRealCamera() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -78,7 +78,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testIsOpened() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -87,7 +87,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testIsOpenedRealCamera() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -101,7 +101,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testOpen() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -116,7 +116,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRead() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -132,7 +132,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRelease() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -147,7 +147,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRetrieveMat() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -164,7 +164,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRetrieveMatInt() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -181,7 +181,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testSet() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } @@ -205,7 +205,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testVideoCaptureInt() { - if (!isEnabled) { + if (!isTestCaseEnabled) { fail("Not yet implemented"); } From 6fb959710dc5c22c852dcc9627f852a1088f1da3 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 12 Nov 2012 18:01:56 +0400 Subject: [PATCH 6/8] Code review comments applied. --- .../dev_with_OCV_on_Android.rst | 132 +++++++++--------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst index 52f7393616..0943b043cd 100644 --- a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst +++ b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst @@ -260,34 +260,35 @@ To build your own Android application, which uses OpenCV from native part, the f #. Either use :ref:`manual ` ``ndk-build`` invocation or :ref:`setup Eclipse CDT Builder ` to build native JNI lib before Java part [re]build and APK creation. -Hello OpenCV Sample -=================== +"Hello OpenCV" Sample +===================== -Here are basic steps to guide you trough the process of creating a simple OpenCV-centric application. +Here are basic steps to guide you trough the creation process of a simple OpenCV-centric application. It will be capable of accessing camera output, processing it and displaying the result. -#. Open Eclipse IDE, create a new clean workspace, create a new Android project (*File -> New -> Android Project*). +#. Open Eclipse IDE, create a new clean workspace, create a new Android project (:guilabel:`File -> New -> Android Project`). -#. Set name, target, package and minSDKVersion accordingly. +#. Set name, target, package and ``minSDKVersion`` accordingly. -#. Add the following permissions to the AndroidManifest.xml file: +#. Add the following permissions to the ``AndroidManifest.xml`` file: .. code-block:: xml :linenos: - + - - - + + + + -#. Reference OpenCV library within your project properties. +#. Reference the OpenCV library within your project properties. .. image:: images/dev_OCV_reference.png :alt: Reference OpenCV library. :align: center -#. Create new view layout for your application, lets name it hello_opencv.xml, and add the following to it: +#. Create new view layout for your application, lets name it ``hello_opencv.xml``, and add the following to it: .. code-block:: xml :linenos: @@ -307,70 +308,71 @@ It will be capable of accessing camera output, processing it and displaying the #. Remove default auto generated layout, if exists. -#. Create a new *Activity* (*New -> Other -> Android -> Android Activity*) and name it, for example: *HelloOpenCVActivity*. Add *CvCameraViewListener* interface to *implementes* section of *HelloOpenCVActivity* class. Add the following code to activity implementation: +#. Create a new ``Activity`` (:guilabel:`New -> Other -> Android -> Android Activity`) and name it, for example: ``HelloOpenCVActivity``. + Add ``CvCameraViewListener`` interface to ``implements`` list of ``HelloOpenCVActivity`` class. Add the following code to activity implementation: .. code-block:: java :linenos: - public class Sample1Java extends Activity implements CvCameraViewListener { - - private CameraBridgeViewBase mOpenCvCameraView; + public class Sample1Java extends Activity implements CvCameraViewListener { - private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { + private CameraBridgeViewBase mOpenCvCameraView; + + 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); + } + } + }; + + /** Called when the activity is first created. */ @Override - public void onManagerConnected(int status) { - switch (status) { - case LoaderCallbackInterface.SUCCESS: { - Log.i(TAG, "OpenCV loaded successfully"); - mOpenCvCameraView.enableView(); - } break; - default: - super.onManagerConnected(status); - } + public void onCreate(Bundle savedInstanceState) { + Log.i(TAG, "called onCreate"); + super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + setContentView(R.layout.hello_opencv); + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.java_surface_view); + mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); + mOpenCvCameraView.setCvCameraViewListener(this); } - }; - /** 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); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - setContentView(R.layout.hello_opencv); - mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.java_surface_view); - mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); - mOpenCvCameraView.setCvCameraViewListener(this); - } + @Override + public void onPause() + { + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); + super.onPause(); + } - @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); + } - @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(); + } - public void onDestroy() { - super.onDestroy(); - if (mOpenCvCameraView != null) - mOpenCvCameraView.disableView(); - } + public void onCameraViewStarted(int width, int height) { + } - public void onCameraViewStarted(int width, int height) { - } + public void onCameraViewStopped() { + } - public void onCameraViewStopped() { + public Mat onCameraFrame(Mat inputFrame) { + return inputFrame; + } } - - public Mat onCameraFrame(Mat inputFrame) { - return inputFrame; - } - } From 9f5fcff3ea86e2cd4f70c786c387ca58c3d2346f Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 13 Nov 2012 10:29:49 +0400 Subject: [PATCH 7/8] More common way of test case disabling implemented. --- .../src/org/opencv/test/OpenCVTestCase.java | 8 +++ .../opencv/test/highgui/VideoCaptureTest.java | 52 ------------------- 2 files changed, 8 insertions(+), 52 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java index 6acf0b34db..71e82841aa 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -175,6 +175,14 @@ public class OpenCVTestCase extends TestCase { super.tearDown(); } + @Override + protected void runTest() throws Throwable { + // Do nothing if the precondition does not hold. + if (isTestCaseEnabled) { + super.runTest(); + } + } + protected Mat getMat(int type, double... vals) { return new Mat(matSize, matSize, type, new Scalar(vals)); diff --git a/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java b/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java index 903768f7bf..ec7211a294 100644 --- a/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java +++ b/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java @@ -25,10 +25,6 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testGet() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); double frameWidth = capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH); @@ -39,10 +35,6 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testGetSupportedPreviewSizes() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); List sizes = capture.getSupportedPreviewSizes(); @@ -54,20 +46,12 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testGrab() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - capture = new VideoCapture(); isSucceed = capture.grab(); assertFalse(isSucceed); } public void testGrabFromRealCamera() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); isSucceed = capture.grab(); @@ -78,19 +62,11 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testIsOpened() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - capture = new VideoCapture(); assertFalse(capture.isOpened()); } public void testIsOpenedRealCamera() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); isOpened = capture.isOpened(); @@ -101,10 +77,6 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testOpen() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - try { capture = new VideoCapture(); capture.open(Highgui.CV_CAP_ANDROID); @@ -116,10 +88,6 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRead() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); isSucceed = capture.read(dst); @@ -132,10 +100,6 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRelease() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.release(); @@ -147,10 +111,6 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRetrieveMat() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.grab(); @@ -164,10 +124,6 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRetrieveMatInt() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.grab(); @@ -181,10 +137,6 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testSet() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 640); @@ -205,10 +157,6 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testVideoCaptureInt() { - if (!isTestCaseEnabled) { - fail("Not yet implemented"); - } - try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); assertNotNull(capture); From 96e4eed018bf6b287927c9576e393bda83899b0f Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 13 Nov 2012 11:41:08 +0400 Subject: [PATCH 8/8] Logcat message for disabled test cases added. --- .../android_test/src/org/opencv/test/OpenCVTestCase.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java index 71e82841aa..b24d858ee3 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -23,8 +23,9 @@ import org.opencv.features2d.DMatch; import org.opencv.features2d.KeyPoint; import org.opencv.highgui.Highgui; -public class OpenCVTestCase extends TestCase { +import android.util.Log; +public class OpenCVTestCase extends TestCase { //change to 'true' to unblock fail on fail("Not yet implemented") public static final boolean passNYI = true; @@ -34,6 +35,8 @@ public class OpenCVTestCase extends TestCase { protected static final double EPS = 0.001; protected static final double weakEPS = 0.5; + private static final String TAG = "OpenCVTestCase"; + protected Mat dst; protected Mat truth; @@ -180,6 +183,8 @@ public class OpenCVTestCase extends TestCase { // Do nothing if the precondition does not hold. if (isTestCaseEnabled) { super.runTest(); + } else { + Log.e(TAG, "Test case \"" + this.getClass().getName() + "\" disabled!"); } }