Example usage for org.opencv.android LoaderCallbackInterface SUCCESS

List of usage examples for org.opencv.android LoaderCallbackInterface SUCCESS

Introduction

In this page you can find the example usage for org.opencv.android LoaderCallbackInterface SUCCESS.

Prototype

int SUCCESS

To view the source code for org.opencv.android LoaderCallbackInterface SUCCESS.

Click Source Link

Document

OpenCV initialization finished successfully.

Usage

From source file:alicrow.opencvtour.FollowTourActivity.java

License:Open Source License

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getIntent().getData() != null) {
        /// FollowTourActivity was launched directly, with a Tour archive. Must initialize OpenCV and load the Tour before we can set up the Activity.
        /// This happens when another app calls our app to open a tour archive.

        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, new BaseLoaderCallback(this) {
            @Override/*w w  w  .  ja  v a 2  s  .co m*/
            public void onManagerConnected(int status) {
                switch (status) {
                case LoaderCallbackInterface.SUCCESS: {
                    Log.i(TAG, "OpenCV loaded successfully");

                    /// Load the tour file
                    Uri data = getIntent().getData();
                    String scheme = data.getScheme();
                    File extracted_folder = null;
                    if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
                        /// content uri
                        try {
                            /// Try to retrieve the filename so we know what to name our extracted folder.
                            String folder_name;
                            Cursor cursor = getContentResolver().query(data, new String[] { "_display_name" },
                                    null, null, null);
                            cursor.moveToFirst();
                            int nameIndex = cursor.getColumnIndex("_display_name");
                            if (nameIndex >= 0) {
                                folder_name = cursor.getString(nameIndex);
                            } else {
                                folder_name = "imported-folder.zip.tour";
                            }
                            cursor.close();

                            folder_name = folder_name.substring(0, folder_name.length() - ".zip.tour".length());
                            extracted_folder = new File(Tour.getImportedToursDirectory(FollowTourActivity.this),
                                    folder_name);
                            Utilities.extractFolder(getContentResolver().openInputStream(data),
                                    extracted_folder.getPath());
                        } catch (FileNotFoundException ex) {
                            Log.e(TAG, ex.getMessage());
                            /// Import failed. Exit the activity.
                            FollowTourActivity.this.finish();
                        }
                    } else {
                        /// regular file uri
                        String filepath = data.getPath();
                        String folder_name = data.getLastPathSegment();
                        folder_name = folder_name.substring(0, folder_name.length() - ".zip.tour".length());
                        extracted_folder = new File(Tour.getImportedToursDirectory(FollowTourActivity.this),
                                folder_name);
                        Utilities.extractFolder(filepath, extracted_folder.getPath());
                    }
                    Tour.setSelectedTour(new Tour(new File(extracted_folder, "tour.yaml")));
                    load(savedInstanceState);
                    break;
                }
                default: {
                    super.onManagerConnected(status);
                    break;
                }
                }
            }
        });
    } else
        load(savedInstanceState);
}

From source file:alicrow.opencvtour.TourListFragment.java

License:Open Source License

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    /// Must wait until OpenCV is initialized before loading the tours (since we load image descriptors).
    BaseLoaderCallback _loader_callback = new BaseLoaderCallback(getActivity()) {
        @Override//from   w ww . j  a v a  2 s  . co m
        public void onManagerConnected(int status) {
            switch (status) {
            case LoaderCallbackInterface.SUCCESS: {
                Log.i(TAG, "OpenCV loaded successfully");

                /// Add footer so the floating action button doesn't cover up the list.
                _adapter = new TourAdapter(Tour.getTours(getActivity()));
                WrapAdapter wrap_adapter = new WrapAdapter(_adapter);
                wrap_adapter.addFooter(getActivity().getLayoutInflater().inflate(R.layout.empty_list_footer,
                        _recycler_view, false));
                _recycler_view.setAdapter(wrap_adapter);
            }
                break;
            default: {
                super.onManagerConnected(status);
            }
                break;
            }
        }
    };

    _recycler_view = (RecyclerView) getActivity().findViewById(R.id.recycler_view);
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, getActivity(), _loader_callback);
    _recycler_view.setLayoutManager(new LinearLayoutManager(getActivity()));

    getActivity().findViewById(R.id.fab).setOnClickListener(this);
    getActivity().findViewById(R.id.help_button).setOnClickListener(this);
}

From source file:android.google.com.basiccamera.UIActivity.java

License:BSD License

protected void onFinishedSurfaceChanged() {
    if (INIT_OPENCV) {
        // Load OpenCV
        if (!OpenCVLoader.initDebug()) {
            Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
            OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
        } else {//from  ww w  .j  av a 2 s .c o m
            Log.d(TAG, "OpenCV library found inside package. Using it!");
            mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
        }
    }
}

From source file:cn.xiongyihui.webcam.ForegroundActivity.java

License:Open Source License

@Override
public void onResume() {
    super.onResume();

    Log.v(TAG, "onResume()");

    if (!OpenCVLoader.initDebug()) {
        Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_10, this, mLoaderCallback);
    } else {//from   ww  w  . j  a va 2  s  . c  o  m
        Log.d(TAG, "OpenCV library found inside package. Using it!");
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }

}

From source file:cn.xiongyihui.webcam.MainActivity.java

License:Open Source License

@Override
public void onResume() {
    super.onResume();

    Log.v(TAG, "onResume()");

    if (!OpenCVLoader.initDebug()) {
        Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_10, this, mLoaderCallback);
    } else {/*from   www  .  j  a v  a  2  s  . co  m*/
        Log.d(TAG, "OpenCV library found inside package. Using it!");
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }

    mIsServiceRunning = isServiceRunning();
    updateButton(mIsServiceRunning);
}

From source file:com.android.cts.verifier.sensors.helpers.OpenCVLibrary.java

License:Apache License

/**
 * Load OpenCV Library in async mode//  w  w w  .  j a v  a2 s.c  o m
 *
 * @param context Activity context.
 * @param allowStatic Allow trying load from local package.
 * @param allowInstall Allow installing package from play store.
 *
 * @return if load succeed return true. Return false otherwise.
 */
public static boolean load(Context context, boolean allowLocal, boolean allowPackage, boolean allowInstall) {
    // only need to load once
    if (!sLoaded) {
        // Try static load first
        if (allowLocal && OpenCVLoader.initDebug()) {
            sLoaded = true;
        } else if (allowPackage) {
            if (allowInstall || probePackage(context)) {
                final CountDownLatch done = new CountDownLatch(1);
                // Load the library through async loader
                OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, context,
                        new BaseLoaderCallback(context) {
                            @Override
                            public void onManagerConnected(int status) {
                                Log.v(TAG, "New Loading status: " + status);
                                switch (status) {
                                case LoaderCallbackInterface.SUCCESS: {
                                    sLoaded = true;
                                }
                                    break;
                                default: {
                                    Log.e(TAG, "Connecting OpenCV Manager failed");
                                }
                                    break;
                                }
                                done.countDown();
                            }
                        });
                try {
                    if (!done.await(ASYNC_LOAD_TIMEOUT_SEC, TimeUnit.SECONDS)) {
                        Log.e(TAG, "Time out when attempt async load");
                    }
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
        }
    }
    return sLoaded;
}

From source file:com.davidmiguel.gobees.monitoring.MonitoringFragment.java

License:Open Source License

@Nullable
@Override/*from  w  ww.j  a va2s  . c  o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.monitoring_frag, container, false);

    // Configure OpenCV callback
    loaderCallback = new BaseLoaderCallback(getContext()) {
        @Override
        public void onManagerConnected(final int status) {
            if (status == LoaderCallbackInterface.SUCCESS) {
                presenter.onOpenCvConnected();
            } else {
                super.onManagerConnected(status);
            }
        }
    };

    // Don't switch off screen
    getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Configure camera
    cameraView = (CameraView) root.findViewById(R.id.camera_view);
    cameraView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_BACK);
    cameraView.setMaxFrameSize(MAX_WIDTH, MAX_HEIGHT);
    // Configure view
    numBeesTV = (TextView) root.findViewById(R.id.num_bees);
    settingsLayout = (RelativeLayout) getActivity().findViewById(R.id.settings);
    chronometer = (Chronometer) root.findViewById(R.id.chronometer);

    // Configure icons
    settingsIcon = (ImageView) root.findViewById(R.id.settings_icon);
    settingsIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            presenter.openSettings();
        }
    });
    recordIcon = (ImageView) root.findViewById(R.id.record_icon);
    recordIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            presenter.startMonitoring();
        }
    });

    // Configure service connection
    mConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder service) {
            MonitoringBinder binder = (MonitoringBinder) service;
            mService = binder.getService(new GoBeesDataSource.SaveRecordingCallback() {
                @Override
                public void onRecordingTooShort() {
                    // Finish activity with error
                    Intent intent = new Intent();
                    intent.putExtra(HiveRecordingsFragment.ARGUMENT_MONITORING_ERROR,
                            HiveRecordingsFragment.ERROR_RECORDING_TOO_SHORT);
                    getActivity().setResult(Activity.RESULT_CANCELED, intent);
                    getActivity().finish();

                }

                @Override
                public void onSuccess() {
                    // Finish activity with OK
                    getActivity().setResult(Activity.RESULT_OK);
                    getActivity().finish();
                }

                @Override
                public void onFailure() {
                    // Finish activity with error
                    Intent intent = new Intent();
                    intent.putExtra(HiveRecordingsFragment.ARGUMENT_MONITORING_ERROR,
                            HiveRecordingsFragment.ERROR_SAVING_RECORDING);
                    getActivity().setResult(Activity.RESULT_CANCELED, intent);
                    getActivity().finish();
                }
            });
            // Set chronometer
            chronometer.setBase(mService.getStartTime());
            chronometer.setVisibility(View.VISIBLE);
            chronometer.start();
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            mService = null;
        }
    };
    return root;
}

From source file:com.davidmiguel.gobees.monitoring.MonitoringService.java

License:Open Source License

/**
 * Config OpenCV (config callback and init OpenCV).
 * When OpenCV is ready, it starts monitoring.
 *//*from w w w . j  ava  2 s  .  co m*/
private void configOpenCv() {
    // OpenCV callback
    BaseLoaderCallback loaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(final int status) {
            if (status == LoaderCallbackInterface.SUCCESS) {
                openCvLoaded = true;
                startMonitoring();
            } else {
                super.onManagerConnected(status);
            }
        }
    };
    // Init openCV
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_2_0, this, loaderCallback);
}

From source file:com.example.sarthuak.opencv.MainActivity.java

@Override
public void onResume() {
    super.onResume();
    if (!OpenCVLoader.initDebug()) {
        Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
        //OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
    } else {/*from  w  w  w  .  j  a  v  a  2 s  .c o m*/
        Log.d(TAG, "OpenCV library found inside package. Using it!");
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }
}

From source file:com.louislepper.waveform.CameraActivity.java

License:Apache License

@Override
public void onResume() {
    super.onResume();
    if (!OpenCVLoader.initDebug()) {
        Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
    } else {//from  w ww . j av a2 s . c o m
        Log.d(TAG, "OpenCV library found inside package. Using it!");
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }
}