From: Alexander Smorkalov Date: Wed, 25 Dec 2013 13:50:15 +0000 (+0400) Subject: CUDA support check added. X-Git-Tag: accepted/tizen/ivi/20140515.103456~1^2~166^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cea9a974348a5fc3779b35014b82e538f3459ec7;p=profile%2Fivi%2Fopencv.git CUDA support check added. --- diff --git a/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java b/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java index 2f6a48a..c1753b6 100644 --- a/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java +++ b/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java @@ -9,8 +9,12 @@ import org.opencv.core.Mat; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2; import org.opencv.imgproc.Imgproc; +import org.opencv.gpu.Gpu; import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.util.Log; import android.view.Menu; @@ -45,10 +49,29 @@ public class Tutorial4Activity extends Activity implements CvCameraViewListener2 { Log.i(TAG, "OpenCV loaded successfully"); - // Load native library after(!) OpenCV initialization - System.loadLibrary("cuda_sample"); - - mOpenCvCameraView.enableView(); + // Check CUDA support + if (Gpu.getCudaEnabledDeviceCount() <= 0) + { + Log.e(TAG, "No CUDA capable device found!"); + AlertDialog InitFailedDialog = new AlertDialog.Builder(Tutorial4Activity.this).create(); + InitFailedDialog.setTitle("OpenCV CUDA error"); + InitFailedDialog.setMessage("CUDA compatible device was not found!"); + InitFailedDialog.setCancelable(false); // This blocks the 'BACK' button + InitFailedDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() { + + public void onClick(DialogInterface dialog, int which) { + Tutorial4Activity.this.finish(); + } + }); + InitFailedDialog.show(); + } + else + { + // Load native library after(!) OpenCV initialization + Log.i(TAG, "Found CUDA capable device!"); + System.loadLibrary("cuda_sample"); + mOpenCvCameraView.enableView(); + } } break; default: {