List of usage examples for org.opencv.android OpenCVLoader initAsync
public static boolean initAsync(String Version, Context AppContext, LoaderCallbackInterface Callback)
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/*from w ww. j a va 2 s .com*/ 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/* w ww . j a v a2s.c o 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 w w w. ja v a 2 s .c o m Log.d(TAG, "OpenCV library found inside package. Using it!"); mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS); } } }
From source file:at.ac.tuwien.ims.weightmonitor.FacialFeatureActivity.java
License:Open Source License
@Override public void onResume() { super.onResume(); if (!error && !openCVLoaded) OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_5, this, mLoaderCallback); }
From source file:at.entenbaer.gui.CameraViewFragment.java
License:Open Source License
@Override public void onResume() { super.onResume(); //OpenCVLoader.initDebug(); OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this.getActivity(), mLoaderCallback); }
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 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.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 {//w ww. ja va2 s .c o 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/*from w ww. ja v a2s . co 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
@Override public void initOpenCV(CvCameraViewListener2 listener) { OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_2_0, getContext(), loaderCallback); cameraView.setCvCameraViewListener(listener); }
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 a v a 2 s .com 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); }