1、This tutorial also assumes you have OpenCV4Android SDK already installed on your development machine and OpenCV Manager on your testing device correspondingly. If you need help with any of these, you may consult our OpenCV4Android SDK tutorial.If you encounter any error after thoroughly following th
2、ese steps, feel free to contact us via OpenCV4Android discussion group or OpenCV Q&A forum . Well do our best to help you out.Using OpenCV Library Within Your Android ProjectIn this section we will explain how to make some existing project to use OpenCV. Starting with 2.4.2 release for Android, Open
3、CV Manager is used to provide apps with the best available version of OpenCV. You can get more information here: Android OpenCV Manager and in these slides.JavaApplication Development with Async InitializationUsing async initialization is a recommended way for application development. It uses the Op
4、enCV Manager to access OpenCV libraries externally installed in the target system.1. Add OpenCV library project to your workspace. Use menu File - Import - Existing project in your workspace.Press Browse button and locate OpenCV4Android SDK (OpenCV-2.4.9-android-sdk/sdk).2. In application project ad
5、d a reference to the OpenCV Java SDK in Project - Properties - Android - Library - Add select OpenCV Library - 2.4.9.In most cases OpenCV Manager may be installed automatically from Google Play. For the case, when Google Play is not available, i.e. emulator, developer board, etc, you can install it
6、manually using adb tool. See How to select the proper version of OpenCV Manager for details.There is a very base code snippet implementing the async initialization. It shows basic principles. See the “15-puzzle” OpenCV sample for details. 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728public
7、 class Sample1Java extends Activity implements CvCameraViewListener private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) Override public void onManagerConnected(int status) switch (status) case LoaderCallbackInterface.SUCCESS: Log.i(TAG, OpenCV loaded successfully); mOpenCvCamer
8、aView.enableView(); break; default: super.onManagerConnected(status); ; public void onResume() super.onResume(); OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback); .It this case application works with OpenCV Manager in asynchronous fashion. OnManagerConnected callback
9、will be called in UI thread, when initialization finishes. Please note, that it is not allowed to use OpenCV calls or load OpenCV-dependent native libs before invoking this callback. Load your own native libraries that depend on OpenCV after the successful OpenCV initialization. Default BaseLoaderCa
10、llback implementation treat application context as Activity and calls Activity.finish() method to exit in case of initialization failure. To override this behavior you need to override finish() method of BaseLoaderCallback class and implement your own finalization method.Application Development with
11、 Static InitializationAccording to this approach all OpenCV binaries are included into your application package. It is designed mostly for development purposes. This approach is deprecated for the production code, release package is recommended to communicate with OpenCV Manager via the async initia
12、lization described above.1. Add the OpenCV library project to your workspace the same way as for the async initialization above. Use menu File - Existing project in your workspace, press Browse button and select OpenCV SDK path (OpenCV-2.4.9-android-sdk/sdk).2. In the application project add a refer
13、ence to the OpenCV4Android SDK in Project - Add select OpenCV Library - 2.4.9;3. If your application project doesnt have a JNI part, just copy the corresponding OpenCV native libs from /sdk/native/libs/ to your project directory to folder libs/.In case of the application project with a JNI part, instead of manual libraries copying you need to modify your Android.mk file: add the following two code lines after the include $(CLEAR_VARS) and before include path_to_OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk12OPENCV_CAMERA_MODULES:=onOP
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1