org.opencv.android.BaseLoaderCallback Java Examples

The following examples show how to use org.opencv.android.BaseLoaderCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MonitoringService.java    From go-bees with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Config OpenCV (config callback and init OpenCV).
 * When OpenCV is ready, it starts monitoring.
 */
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);
}
 
Example #2
Source File: FDOpenCVPresenter.java    From Image-Detection-Samples with Apache License 2.0 5 votes vote down vote up
public BaseLoaderCallback getLoader(final Context context, final CameraBridgeViewBase openCvCameraView) {
    return new BaseLoaderCallback(context) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                    Log.i(TAG, "OpenCV loaded successfully");
                    try {
                        /** load face classificator */
                        File cascadeFileFace = FileHelper.readCascadeFile(context,
                                R.raw.haarcascade_frontalface_alt2,
                                "cascade", "haarcascade_front.xml");
                        detectorFace = initializeJavaDetector(cascadeFileFace);
                        cascadeFileFace.delete();
                        /** load eye classificator */
                        File cascadeFileEye = FileHelper.readCascadeFile(context,
                                R.raw.haarcascade_eye_tree_eyeglasses,
                                "cascadeER", "haarcascade_eye.xml");
                        detectorEye = initializeJavaDetector(cascadeFileEye);
                        cascadeFileEye.delete();
                        setMachineLearningMechanism();
                    } catch (IOException e) {
                        e.printStackTrace();
                        Log.e(TAG, "Failed to load cascade. Exception thrown: " + e);
                    }

                    setCameraParameters(openCvCameraView);

                    break;
                default:
                    super.onManagerConnected(status);
                    break;
            }
        }
    };
}
 
Example #3
Source File: MainActivity.java    From SoftwarePilot with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        checkAndRequestPermissions();
    }

    setContentView(R.layout.activity_main);

    mHandler = new Handler(Looper.getMainLooper());

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
    /*
    ActivityCompat.requestPermissions(this,
            new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.INTERNET, Manifest.permission.VIBRATE,
                    Manifest.permission.ACCESS_WIFI_STATE,
                    Manifest.permission.WAKE_LOCK, Manifest.permission.ACCESS_COARSE_LOCATION,
                    Manifest.permission.ACCESS_NETWORK_STATE, Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.CHANGE_WIFI_STATE, Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS,
                    Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.SYSTEM_ALERT_WINDOW,
                    Manifest.permission.READ_PHONE_STATE,
            }
            , 1);
    */

    if(!OpenCVLoader.initDebug()){
        Log.v(TAG, "OpenCV not loaded");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_11, this,
                new BaseLoaderCallback(this) {
            @Override
            public void onManagerConnected(int status) {
                switch (status) {
                    case LoaderCallbackInterface.SUCCESS:
                    {
                        Log.i("OpenCV", "OpenCV loaded successfully");
                        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
                        CascadeClassifier tt = new CascadeClassifier();

                        Mat imageMat=new Mat();
                    } break;
                    default:
                    {
                        super.onManagerConnected(status);
                    } break;
                }
            }
        });
    } else {
        Log.v(TAG, "OpenCV loaded");
    }


    /*DJISDKManager.getInstance().registerApp(MainActivity.this.getApplicationContext(), mDJISDKManagerCallback);

    while (hasRegistered == false) {
        System.out.println("No Registration Loop");
        try {
            Thread.sleep(10000);
        } catch (Exception e) {
        }
        DJISDKManager.getInstance().registerApp(MainActivity.this.getApplicationContext(), mDJISDKManagerCallback);
    }*/
}
 
Example #4
Source File: FaceFragment.java    From OpenCV-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onManagerConnected(int status) {
    super.onManagerConnected(status);
    Snackbar.make(cameraView, status == BaseLoaderCallback.SUCCESS ? "OpenCV Load Success." : "OpenCV Load Failed.", Snackbar.LENGTH_SHORT).show();
    cameraView.enableView();
}
 
Example #5
Source File: ImageFragment.java    From OpenCV-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onManagerConnected(int status) {
    super.onManagerConnected(status);
    Snackbar.make(ivOrigin, status == BaseLoaderCallback.SUCCESS ? "OpenCV Load Success." : "OpenCV Load Failed.", Snackbar.LENGTH_SHORT).show();
}
 
Example #6
Source File: FaceDetectionUtils.java    From AndroidFaceRecognizer with MIT License 4 votes vote down vote up
public static void initialize(Context context){
	mContext = context;
	faceDataSource = new FacesDataSource(context);
	mLoaderCallback = new BaseLoaderCallback(context) {
        @Override
        public void onManagerConnected(int status) {
        	System.out.println("---------------------------- status: "+status);
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                	
            		new Thread(new Runnable() {
            			
            			@Override
            			public void run() {
            				System.loadLibrary("native_camera_r2.2.0");
            				System.loadLibrary("native_camera_r2.3.3");
            				System.loadLibrary("native_camera_r3.0.1");
            				System.loadLibrary("native_camera_r4.0.0");
            				System.loadLibrary("native_camera_r4.0.3");
            				System.loadLibrary("native_camera_r4.1.1");
            				System.loadLibrary("native_camera_r4.2.0");
            				System.loadLibrary("opencv_java");
            				System.loadLibrary("detection_and_recognition_lib");
            				loadCascadeFiles();
            				cascadeFilesLoaded = true;
            			}
            		}).start();
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
        
        @Override
        public void onPackageInstall(int operation,
        		InstallCallbackInterface callback) {
        	System.out.println("---------------------------------------- onPackageInstall");
        	//super.onPackageInstall(operation, callback);
        	/*System.loadLibrary("native_camera_r2.2.0");
System.loadLibrary("native_camera_r2.3.3");
System.loadLibrary("native_camera_r3.0.1");
System.loadLibrary("native_camera_r4.0.0");
System.loadLibrary("native_camera_r4.0.3");
System.loadLibrary("native_camera_r4.1.1");*/
System.loadLibrary("native_camera_r4.2.0");
System.loadLibrary("opencv_java");
System.loadLibrary("detection_and_recognition_lib");
loadCascadeFiles();
cascadeFilesLoaded = true;
        }
    };
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, context.getApplicationContext(), mLoaderCallback);
}