1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.cts.verifier.sensors.helpers; 17 18 import android.content.Context; 19 import android.os.Looper; 20 import android.util.Log; 21 22 import org.opencv.android.BaseLoaderCallback; 23 import org.opencv.android.LoaderCallbackInterface; 24 import org.opencv.android.OpenCVLoader; 25 26 import java.util.concurrent.CountDownLatch; 27 28 /** 29 * OpenCV library loader class 30 */ 31 public class OpenCVLibrary { 32 33 private static String TAG = "OpenCVLibraryProbe"; 34 private static boolean mLoaded = false; 35 36 /** 37 * Load OpenCV Library in async mode 38 * @param context Activity context 39 */ loadAsync(Context context)40 public static void loadAsync(Context context) { 41 // only need to load once 42 if (isLoaded()) return; 43 44 // Load the library through loader 45 OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, context, 46 new BaseLoaderCallback(context) { 47 @Override 48 public void onManagerConnected(int status) { 49 Log.v(TAG, "New Loading status: "+status); 50 switch (status) { 51 case LoaderCallbackInterface.SUCCESS: { 52 mLoaded = true; 53 } 54 break; 55 default: { 56 super.onManagerConnected(status); 57 } 58 break; 59 } 60 } 61 }); 62 } 63 64 /** 65 * Test if the library is loaded 66 * @return a boolean indicates whether the OpenCV library is loaded. 67 */ isLoaded()68 public static boolean isLoaded() { 69 return mLoaded; 70 } 71 } 72