Basic implementation of LoaderCallbackInterface. Logic of this implementation is well-described by the following scheme:
Basic implementation of ``LoaderCallbackInterface``. Logic of this implementation is
well-described by the following scheme:
.. image:: img/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.
There is a very base code snippet implementing the async initialization with ``BaseLoaderCallback``.
See the "15-puzzle" OpenCV sample for details.
.. code-block:: java
:linenos:
...
...
@@ -42,7 +44,7 @@ There is a very base code snippet implementing the async initialization with Bas
@Override
protected void onResume()
{
Log.i(TAG, "called onResume");
Log.i(TAG, "Called onResume");
super.onResume();
Log.i(TAG, "Trying to load OpenCV library");
...
...
@@ -55,6 +57,7 @@ There is a very base code snippet implementing the async initialization with Bas
Using in Service
----------------
Default BaseLoaderCallback 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.
Default ``BaseLoaderCallback`` implementation treats 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
OpenCV Manager is an Android service targeted to manage OpenCV library binaries on end users devices. It allows sharing the OpenCV dynamic libraries of different versions between applications on the same device. The Manager provides the following benefits\:
OpenCV Manager is an Android service targeted to manage OpenCV library binaries on end users devices.
It allows sharing the OpenCV dynamic libraries between applications on the same device. The Manager
provides the following benefits\:
#. Less memory usage. All apps use the same binaries from service and do not keep native libs inside themselves;
#. Hardware specific optimizations for all supported platforms;
#. Trusted OpenCV library source. All packages with OpenCV are published on Google Play service;
#. Trusted OpenCV library source. All packages with OpenCV are published on Google Play market;
#. Regular updates and bug fixes;
Usage model for target user
---------------------------
Usage model for end user
------------------------
.. image:: img/AndroidAppUsageModel.png
First OpenCV app\:
#. Any OpenCV-dependent app is installed from Google Play marketplace or manually;
#. At the first launch, it suggests installing OpenCV Manager;
#. Then OpenCV Manager is downloaded and installed, using Google Play marketplace service.
#. When Manager has ben started, the application suggests installing OpenCV library for the target device trough Google Play marketplace if it is necessary;
#. After installation is finished, the app may be launched to perform common tasks.
#. At the first launch, it suggests installation of OpenCV Manager;
#. Then OpenCV Manager is downloaded and installed, using the Google Play application.
#. When Manager has been started, the application suggests installation of OpenCV library for the
target device architecture if it is necessary;
#. After the installation is finished, the app may be launched.
Next OpenCV app\:
Subsequent launches of OpenCV apps\:
#. Any OpenCV-dependent app is installed from Google Play marketplace or manually;
#. Any OpenCV-dependent app is installed from Google Play market or manually;
#. At the first launch, the app starts as usually;
#. If the selected version is not installed, OpenCV Manager suggests installing OpenCV library for the target device trough Google Play marketplace;
#. After installation is finished, the app may be launched to perform common tasks.
#. If the selected OpenCV version is not installed, OpenCV Manager suggests installing OpenCV
library for the target device through Google Play marketplace;
#. After the installation is finished, the app may be launched.
Loads and initializes OpenCV library from within current application package. Roughly it is analog of ``system.loadLibrary("opencv_java")``.
Loads and initializes OpenCV library from within current application package. Roughly it is
analog of ``system.loadLibrary("opencv_java")``.
:rtype: boolean;
:return: returns true if initialization of OpenCV was successful.
.. note:: This method is deprecated for production code. It is designed for experimantal and local development purposes only. If you want to publish your app use approach with async initialization.
.. note:: This method is deprecated for production code. It is designed for experimental and local
development purposes only. If you want to publish your app use approach with async
@@ -186,6 +186,8 @@ Import OpenCV library and samples to the Eclipse
Each sample included into the |opencv_android_bin_pack| is a regular Android project that already
references OpenCV library.Follow the steps below to import OpenCV and samples into the workspace:
.. note:: OpenCV samples are indeed **dependent** on OpenCV library project so don't forget to import it to your workspace as well.
* Right click on the :guilabel:`Package Explorer` window and choose :guilabel:`Import...` option
from the context menu:
...
...
@@ -213,13 +215,21 @@ Import OpenCV library and samples to the Eclipse
and you have to wait some time while it is building OpenCV samples. Just give a minute to
Eclipse to complete initialization.
.. note :: After the initial import, on a non-Windows (Linux and Mac OS) operating system Eclipse
.. warning :: After the initial import, on a non-Windows (Linux and Mac OS) operating system Eclipse
will still show build errors for applications with native C++ code. To resolve the
issues, please do the following:
Open :guilabel:`Project Properties -> C/C++ Build`, and replace "Build command" text
to ``"${NDKROOT}/ndk-build"`` (remove .cmd at the end).
.. note :: In some cases the build errors don't disappear, then try the following actions:
* right click on ``OpenCV Library`` project -> :guilabel:`Android Tools -> Fix Project Properties`,
then menu :guilabel:`Project -> Clean... -> Clean all`
* right click on the project with errors -> :guilabel:`Properties -> Android`, make sure the
``Target`` is selected and is ``Android 3.0`` or higher
* check the build errors in the :guilabel:`Problems` view window and try to resolve them by yourselves
.. image:: images/eclipse_cdt_cfg4.png
:alt: Configure CDT
:align: center
...
...
@@ -235,14 +245,14 @@ Import OpenCV library and samples to the Eclipse
Running OpenCV Samples
----------------------
At this point you should be able to build and run the samples. Keep in mind, that ``face-detection``,
``Tutorial 3`` and ``Tutorial 4`` include some native code and require Android NDK and CDT plugin
for Eclipse to build working applications. If you haven't installed these tools see the corresponding
section of :ref:`Android_Dev_Intro`.
At this point you should be able to build and run the samples. Keep in mind, that
``face-detection``, ``Tutorial 3` and ``Tutorial 4`` include some native code and
require Android NDK and CDT plugin for Eclipse to build working applications. If you haven't
installed these tools, see the corresponding section of :ref:`Android_Dev_Intro`.
Also, please consider that ``Tutorial 0`` and ``Tutorial 1`` samples use Java Camera API that
definitelly accessible on emulator from the Android SDK.
Other samples use OpenCV Native Camera which may not work with emulator.
.. warning:: Please consider that some samples use Android Java Camera API, which is accessible
with an AVD. But most of samples use OpenCV Native Camera which **may not work** with
an emulator.
.. note:: Recent *Android SDK tools, revision 19+* can run ARM v7a OS images but they available not
for all Android versions.
...
...
@@ -282,6 +292,40 @@ Well, running samples from Eclipse is very simple:
If you have no access to the *Market*, which is often the case with emulators - you will need to install the packages from OpenCV4Android SDK folder manually. See :ref:`manager_selection` for details.