OpenCVLibrary.java revision 6133d242700c535ff82f13becd904e330a2f79cb
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 */
16package com.android.cts.verifier.sensors.helpers;
17
18import android.content.Context;
19import android.os.Looper;
20import android.util.Log;
21
22import org.opencv.android.BaseLoaderCallback;
23import org.opencv.android.LoaderCallbackInterface;
24import org.opencv.android.OpenCVLoader;
25
26import java.util.concurrent.CountDownLatch;
27
28/**
29 * OpenCV library loader class
30 */
31public 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     */
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_3_0_0, 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     */
68    public static boolean isLoaded() {
69        return mLoaded;
70    }
71}
72