Opencv interface 中的BaseLOaderCallback

来源:互联网 发布:知乎 电脑版 编辑:程序博客网 时间:2024/05/22 00:31

Base Loader Callback Interface Implementation

class BaseLoaderCallback

Basic implementation of LoaderCallbackInterface. Logic of this implementation iswell-described by the following scheme:

../../../_images/AndroidAppUsageModel.png

Using in Java Activity

There is a very base code snippet implementing the async initialization with BaseLoaderCallback.See the “15-puzzle” OpenCV sample for details.

 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334
public class MyActivity extends Activity implements HelperCallbackInterface{private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {   @Override   public void onManagerConnected(int status) {     switch (status) {       case LoaderCallbackInterface.SUCCESS:       {          Log.i(TAG, "OpenCV loaded successfully");          // Create and set View          mView = new puzzle15View(mAppContext);          setContentView(mView);       } break;       default:       {          super.onManagerConnected(status);       } break;     }   }};/** Call on every application resume **/@Overrideprotected void onResume(){    Log.i(TAG, "Called onResume");    super.onResume();    Log.i(TAG, "Trying to load OpenCV library");    if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_4, this, mOpenCVCallBack))    {        Log.e(TAG, "Cannot connect to OpenCV Manager");    }}

Using in Service

Default BaseLoaderCallback implementation treats application context asActivity and callsActivity.finish() method to exit in case of initialization failure.To override this behavior you need to overridefinish() method of BaseLoaderCallback classand implement your own finalization method.

0 0