Example usage for org.opencv.android OpenCVLoader OPENCV_VERSION_2_4_7

List of usage examples for org.opencv.android OpenCVLoader OPENCV_VERSION_2_4_7

Introduction

In this page you can find the example usage for org.opencv.android OpenCVLoader OPENCV_VERSION_2_4_7.

Prototype

String OPENCV_VERSION_2_4_7

To view the source code for org.opencv.android OpenCVLoader OPENCV_VERSION_2_4_7.

Click Source Link

Document

OpenCV Library version 2.4.7.

Usage

From source file:ve.ucv.ciens.ccg.nxtar.MainActivity.java

License:Apache License

/**
 * <p>Initializes this activity</p>
 * /*from   ww  w  .  j a  v  a 2 s.c om*/
 * <p>This method handles the initialization of LibGDX and OpenCV. OpenCV is
 * loaded the asynchronous method if the devices is not an OUYA console.</p>
 * 
 * @param savedInstanceState The application state if it was saved in a previous run.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    cameraCalibrated = false;

    // Set screen orientation. Portrait on mobile devices, landscape on OUYA.
    if (!Ouya.runningOnOuya) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }

    // Set up the Android related variables.
    uiHandler = new Handler();
    uiContext = this;
    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    // Attempt to initialize OpenCV.
    if (!Ouya.runningOnOuya) {
        // If running on a moble device, use the asynchronous method aided
        // by the OpenCV Manager app.
        loaderCallback = new BaseLoaderCallback(this) {
            @Override
            public void onManagerConnected(int status) {
                switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                    // If successfully initialized then load the native method implementations and
                    // initialize the static matrices.
                    System.loadLibrary("cvproc");
                    ocvOn = true;
                    cameraMatrix = new Mat();
                    distortionCoeffs = new Mat();
                    break;

                default:
                    Toast.makeText(uiContext, R.string.ocv_failed, Toast.LENGTH_LONG).show();
                    ocvOn = false;
                    break;
                }
            }
        };

        // Launch the asynchronous initializer.
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_7, this, loaderCallback);

    } else {
        // If running on an OUYA device.
        if (ocvOn) {
            // If OpenCV loaded successfully then initialize the native matrices.
            cameraMatrix = new Mat();
            distortionCoeffs = new Mat();
        } else {
            Toast.makeText(uiContext, R.string.ocv_failed, Toast.LENGTH_LONG).show();
        }
    }

    // Configure LibGDX.
    AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
    cfg.useAccelerometer = true;
    cfg.useCompass = true;
    cfg.useWakelock = true;

    // Launch the LibGDX core game class.
    initialize(new NxtARCore(this), cfg);
}