Merged the trunk r8595:8668 (except iOS and new gpu functionality)
@@ -5,14 +5,15 @@
|
||||
Using Android binary package with Eclipse
|
||||
*****************************************
|
||||
|
||||
This tutorial was tested using Ubuntu 10.04 and Windows 7 SP1 operating systems. Nevertheless, it should also work on any other **OS**\ es supported by Android SDK (including Mac OS X). If you encounter errors after following the steps described here, feel free to contact us via *android-opencv* discussion group https://groups.google.com/group/android-opencv/ and we will try to help you.
|
||||
This tutorial was tested using Ubuntu 10.04 and Windows 7 SP1 operating systems.
|
||||
Nevertheless, it should also work on any other **OS**\ es supported by Android SDK (including Mac OS X).
|
||||
If you encounter errors after following the steps described here, feel free to contact us via `android-opencv <https://groups.google.com/group/android-opencv/>`_ discussion group and we will try to help you.
|
||||
|
||||
Quick environment setup for Android development
|
||||
===============================================
|
||||
|
||||
If you are making a clean environment installation then you can try **T**\ egra **A**\ ndroid **D**\ evelopment **P**\ ack (*TADP*) released by *NVIDIA*:
|
||||
|
||||
http://developer.nvidia.com/tegra-android-development-pack
|
||||
If you are making a clean environment installation then you can try `Tegra Android Development Pack <http://developer.nvidia.com/tegra-android-development-pack>`_
|
||||
(**TADP**) released by **NVIDIA**:
|
||||
|
||||
It will cover all of the environment set up automatically and you can go to the next step :ref:`Get_the_OpenCV_package_for_Android_development` right after automatic setup.
|
||||
|
||||
@@ -45,9 +46,10 @@ You need the following tools to be installed:
|
||||
|
||||
#. **Sun JDK 6**
|
||||
|
||||
Visit http://www.oracle.com/technetwork/java/javase/downloads/index.html and download installer for your OS.
|
||||
Visit `Java SE Downloads page <http://www.oracle.com/technetwork/java/javase/downloads/>`_ and download installer for your OS.
|
||||
|
||||
Here is a detailed :abbr:`JDK (Java Development Kit)` installation guide for Ubuntu and Mac OS: http://source.android.com/source/initializing.html#installing-the-jdk (only JDK sections are applicable for OpenCV)
|
||||
Here is a detailed :abbr:`JDK (Java Development Kit)` `installation guide <http://source.android.com/source/initializing.html#installing-the-jdk>`_
|
||||
for Ubuntu and Mac OS (only JDK sections are applicable for OpenCV)
|
||||
|
||||
.. note:: OpenJDK is not usable for Android development because Android SDK supports only Sun JDK.
|
||||
If you use Ubuntu, after installation of Sun JDK you should run the following command to set Sun java environment:
|
||||
@@ -58,9 +60,9 @@ You need the following tools to be installed:
|
||||
|
||||
#. **Android SDK**
|
||||
|
||||
Get the latest Android SDK from http://developer.android.com/sdk/index.html
|
||||
Get the latest ``Android SDK`` from http://developer.android.com/sdk/index.html
|
||||
|
||||
Here is Google's install guide for SDK http://developer.android.com/sdk/installing.html
|
||||
Here is Google's `install guide <http://developer.android.com/sdk/installing.html>`_ for SDK.
|
||||
|
||||
.. note:: If you choose SDK packed into Windows installer, then you should have 32-bit JRE installed. It is not needed for Android development, but installer is x86 application and requires 32-bit Java runtime.
|
||||
|
||||
@@ -80,36 +82,34 @@ You need the following tools to be installed:
|
||||
|
||||
You need the following SDK components to be installed:
|
||||
|
||||
* *Android SDK Tools, revision12* or newer
|
||||
* *Android SDK Tools, revision14* or newer
|
||||
|
||||
Older revisions should also work, but they are not recommended.
|
||||
|
||||
* *SDK Platform Android 2.2, API 8, revision 2* (also known as *android-8*)
|
||||
|
||||
This is minimal platform supported by OpenCV Java API. And it is set as default for OpenCV distribution. It is possible to use newer platform with OpenCV package, but it requires to edit OpenCV project settings.
|
||||
* *SDK Platform Android 3.0, API 11* (also known as *android-11*)
|
||||
|
||||
The minimal platform supported by OpenCV Java API is **Android 2.2** (API 8). This is also the minimum API Level required for the provided samples to run.
|
||||
See the ``<uses-sdk android:minSdkVersion="8"/>`` tag in their **AndroidManifest.xml** files.
|
||||
But for successful compilation of some samples the **target** platform should be set to Android 3.0 (API 11) or higher. It will not block them from running on Android 2.2+.
|
||||
|
||||
.. image:: images/android_sdk_and_avd_manager.png
|
||||
:height: 400px
|
||||
:alt: Android SDK and AVD manager
|
||||
:height: 500px
|
||||
:alt: Android SDK Manager
|
||||
:align: center
|
||||
|
||||
See `Adding SDK Components
|
||||
<http://developer.android.com/sdk/adding-components.html>`_ for help with installing/updating SDK components.
|
||||
See `Adding SDK Components <http://developer.android.com/sdk/adding-components.html>`_ for help with installing/updating SDK components.
|
||||
|
||||
#. **Eclipse IDE**
|
||||
|
||||
Check the `Android SDK System Requirements
|
||||
<http://developer.android.com/sdk/requirements.html>`_ document for a list of Eclipse versions that are compatible with the Android SDK.
|
||||
For OpenCV 2.4.0 we recommend Eclipse 3.6 (Helios) or later versions. They work well for OpenCV under both Windows and Linux.
|
||||
Check the `Android SDK System Requirements <http://developer.android.com/sdk/requirements.html>`_ document for a list of Eclipse versions that are compatible with the Android SDK.
|
||||
For OpenCV 2.4.0 we recommend Eclipse 3.7 (Indigo) or later versions. They work well for OpenCV under both Windows and Linux.
|
||||
|
||||
If you have no Eclipse installed, you can download it from this location:
|
||||
|
||||
http://www.eclipse.org/downloads/
|
||||
If you have no Eclipse installed, you can get it from the `download page <http://www.eclipse.org/downloads/>`_.
|
||||
|
||||
#. **ADT plugin for Eclipse**
|
||||
|
||||
This instruction is copied from http://developer.android.com/sdk/eclipse-adt.html#downloading
|
||||
. Please, visit that page if you have any troubles with ADT plugin installation.
|
||||
This instruction is copied from `Android Developers site <http://developer.android.com/sdk/eclipse-adt.html>`_.
|
||||
Please, visit `that page <http://developer.android.com/sdk/eclipse-adt.html#downloading>`_ if you have any troubles with :abbr:`ADT(Android Development Tools)` plugin installation.
|
||||
|
||||
Assuming that you have Eclipse IDE installed, as described above, follow these steps to download and install the ADT plugin:
|
||||
|
||||
@@ -136,7 +136,7 @@ You need the following tools to be installed:
|
||||
Get the OpenCV package for Android development
|
||||
==============================================
|
||||
|
||||
#. Go to the http://sourceforge.net/projects/opencvlibrary/files/opencv-android/ and download the latest available version. Currently it is |opencv_android_bin_pack_url|_
|
||||
#. Go to the `OpenCV dowload page on SourceForge <http://sourceforge.net/projects/opencvlibrary/files/opencv-android/>`_ and download the latest available version. Currently it is |opencv_android_bin_pack_url|_
|
||||
|
||||
#. Create new folder for Android+OpenCV development.
|
||||
|
||||
@@ -175,23 +175,29 @@ Open OpenCV library and samples in Eclipse
|
||||
:alt: Choosing C:\Work\android-opencv\ as workspace location
|
||||
:align: center
|
||||
|
||||
#. Configure your ADT plugin
|
||||
#. Configure your ADT plugin (if needed)
|
||||
|
||||
.. important:: ADT plugin settings are workspace-dependent. So you have to repeat this step each time when you create a new workspace.
|
||||
.. important:: In most cases the ADT plugin finds Android SDK automatically, but sometimes it fails and shows the following prompt:
|
||||
|
||||
Once you have created a new workspace, you have to point the ADT plugin to the Android SDK directory. This setting is stored in workspace metadata, as result this step is required each time when you are creating new workspace for Android development. See `Configuring the ADT Plugin
|
||||
<http://developer.android.com/sdk/eclipse-adt.html#configuring>`_ document for the original instructions from *Google*.
|
||||
.. image:: images/eclipse_1a_locate_sdk.png
|
||||
:alt: Locating Android SDK
|
||||
:align: center
|
||||
|
||||
Select :guilabel:`Use existing SDKs` option, browse for Android SDK folder and click :guilabel:`Finish`.
|
||||
|
||||
To make sure the SDK folder is set correctly do the following step taken from `Configuring the ADT Plugin <http://developer.android.com/sdk/eclipse-adt.html#configuring>`_ document from *Google*:
|
||||
|
||||
* Select :menuselection:`Window --> Preferences...` to open the Preferences panel (Mac OS X: :menuselection:`Eclipse --> Preferences`):
|
||||
|
||||
.. image:: images/eclipse_2_window_preferences.png
|
||||
:height: 400px
|
||||
:alt: Select Window > Preferences...
|
||||
:align: center
|
||||
|
||||
* Select :guilabel:`Android` from the left panel.
|
||||
|
||||
You may see a dialog asking whether you want to send usage statistics to *Google*. If so, make your choice and click :guilabel:`Proceed`. You cannot continue with this procedure until you click :guilabel:`Proceed`.
|
||||
You may see a dialog asking whether you want to send usage statistics to *Google*. If so, make your choice and click :guilabel:`Proceed`. You cannot continue with this procedure until you click :guilabel:`Proceed`.
|
||||
|
||||
If the SDK folder isn't set you'll see the following:
|
||||
|
||||
.. image:: images/eclipse_3_preferences_android.png
|
||||
:alt: Select Android from the left panel
|
||||
@@ -199,7 +205,9 @@ Open OpenCV library and samples in Eclipse
|
||||
|
||||
* For the SDK Location in the main panel, click :guilabel:`Browse...` and locate your Android SDK directory.
|
||||
|
||||
* Click :guilabel:`Apply` button at the bottom right corner of main panel:
|
||||
* Click :guilabel:`Apply` button at the bottom right corner of main panel.
|
||||
|
||||
If the SDK folder is already set correctly you'll see something like this:
|
||||
|
||||
.. image:: images/eclipse_4_locate_sdk.png
|
||||
:alt: Locate Android SDK
|
||||
@@ -245,6 +253,20 @@ Open OpenCV library and samples in Eclipse
|
||||
|
||||
To help Eclipse to understand that there are no any errors choose OpenCV library in :guilabel:`Package Explorer` (left mouse click) and press :kbd:`F5` button on your keyboard. Then choose any sample (except first samples in *Tutorial Base* and *Tutorial Advanced*) and also press :kbd:`F5`.
|
||||
|
||||
Sometimes more advanced manipulations are needed:
|
||||
|
||||
* The provided projects are configured for `android-11` target that can be missing platform in your Android SDK. After right click on any project select :guilabel:`Properties` and then :guilabel:`Android` on the left pane. Click some target with `API Level` 11 or higher:
|
||||
|
||||
.. image:: images/eclipse_8a_target.png
|
||||
:alt: Updating target
|
||||
:align: center
|
||||
|
||||
* Sometimes a project needs fixing its project properties. After right click on any project select :guilabel:`Android Tools` and then :guilabel:`Fix Project Properties` in sub-menu:
|
||||
|
||||
.. image:: images/eclipse_8b_fix_props.png
|
||||
:alt: Fixing project properties
|
||||
:align: center
|
||||
|
||||
After this manipulation Eclipse will rebuild your workspace and error icons will disappear one after another:
|
||||
|
||||
.. image:: images/eclipse_9_errors_dissapearing.png
|
||||
@@ -257,16 +279,14 @@ Open OpenCV library and samples in Eclipse
|
||||
:alt: OpenCV package imported into Eclipse
|
||||
:align: center
|
||||
|
||||
.. note:: If you are importing only OpenCV library without samples then instead of second refresh command (:kbd:`F5`) you might need to make :menuselection:`Android Tools --> Fix Project Properties` from project context menu.
|
||||
|
||||
Running OpenCV Samples
|
||||
======================
|
||||
|
||||
At this point you should be able to build and run all samples except two from Advanced tutorial (these samples require Android NDK to build working applications, see the next tutorial :ref:`Android_Binary_Package_with_NDK` to learn how to compile them).
|
||||
|
||||
Also I want to note that only ``Tutorial 1 Basic - 0. Android Camera`` and ``Tutorial 1 Basic - 1. Add OpenCV`` samples are able to run on Emulator from Android SDK. Other samples are using OpenCV Native Camera which does not work with emulator.
|
||||
Also I want to note that only ``Tutorial 0 - Android Camera`` and ``Tutorial 1 - Add OpenCV`` samples are able to run on Emulator from Android SDK. Other samples are using OpenCV Native Camera which does not work with emulator.
|
||||
|
||||
.. note:: Latest *Android SDK tools, revision 12* can run ARM v7 OS images but *Google* does not provide such images with SDK.
|
||||
.. note:: Latest *Android SDK tools, revision 19* can run ARM v7a OS images but *Google* provides such image for Android 4.x only.
|
||||
|
||||
Well, running samples from Eclipse is very simple:
|
||||
|
||||
@@ -290,7 +310,7 @@ Well, running samples from Eclipse is very simple:
|
||||
|
||||
* Select the :guilabel:`Android Application` option and click :guilabel:`OK` button. Eclipse will install and run the sample.
|
||||
|
||||
Here is ``Tutorial 1 Basic - 1. Add OpenCV`` sample detecting edges using Canny algorithm from OpenCV:
|
||||
Here is ``Tutorial 1 - Add OpenCV`` sample detecting edges using Canny algorithm from OpenCV:
|
||||
|
||||
.. image:: images/emulator_canny.png
|
||||
:height: 600px
|
||||
|
@@ -17,17 +17,18 @@ This tutorial describes a fast way how to create and build Android applications
|
||||
Please note that before starting this tutorial you should fulfill all the steps, described in the tutorial :ref:`Android_Binary_Package`.
|
||||
|
||||
This tutorial was tested using Ubuntu 10.04 and Windows 7 SP1 operating systems.
|
||||
Nevertheless, it should also work on Mac OS X. If you encounter errors after following the steps described here, feel free to contact us via *android-opencv* discussion group https://groups.google.com/group/android-opencv/ and we will try to help you.
|
||||
Nevertheless, it should also work on Mac OS X. If you encounter errors after following the steps described here, feel free to contact us via
|
||||
`android-opencv <https://groups.google.com/group/android-opencv/>`_ discussion group and we will try to help you.
|
||||
|
||||
|
||||
Prerequisites: Setup NDK
|
||||
========================
|
||||
|
||||
To compile C++ code for Android platform you need Android **N**\ ative **D**\ evelopment **K**\ it (*NDK*).
|
||||
To compile C++ code for Android platform you need ``Android Native Development Kit`` (*NDK*).
|
||||
|
||||
You can get the latest version of NDK from the page http://developer.android.com/sdk/ndk/index.html .
|
||||
You can get the latest version of NDK from the `download page <http://developer.android.com/sdk/ndk/index.html>`_.
|
||||
|
||||
To install Android NDK just extract the archive to some folder on your computer. (Here is installation instructions on the NDK home page: http://developer.android.com/sdk/ndk/index.html#installing)
|
||||
To install Android NDK just extract the archive to some folder on your computer. (Here is `installation instructions <http://developer.android.com/sdk/ndk/index.html#installing>`_ on the NDK home page.)
|
||||
|
||||
.. note:: Before start you can read official Android NDK documentation which is in the Android NDK archive, in the folder :file:`docs/`.
|
||||
|
||||
@@ -53,7 +54,7 @@ Usually code of an Android application has the following structure:
|
||||
|
||||
- :file:`AndroidManifest.xml`
|
||||
|
||||
- :file:`default.properties`
|
||||
- :file:`project.properties`
|
||||
|
||||
- :file:`... other files ...`
|
||||
|
||||
@@ -77,11 +78,13 @@ Also the root folder should contain the following files
|
||||
|
||||
It can be created using Eclipse wizard or :command:`android` tool from Android SDK
|
||||
|
||||
* :file:`default.properties` is a text file containing information about target Android platform and other build details.
|
||||
* :file:`project.properties` is a text file containing information about target Android platform and other build details.
|
||||
|
||||
This file is generated by Eclipse or can be created with :command:`android` tool from Android SDK
|
||||
|
||||
.. note:: Both files (:file:`AndroidManifest.xml` and :file:`default.properties`) are required to compile the C++ part of the application (NDK build system uses information from these files). If any of these files does not exist, compile the Java part of the project before the C++ part.
|
||||
.. note:: Both files (:file:`AndroidManifest.xml` and :file:`project.properties`) are required to compile the C++ part of the application (NDK build system uses information from these files). If any of these files does not exist, compile the Java part of the project before the C++ part.
|
||||
|
||||
.. _NDK_build_cli:
|
||||
|
||||
|
||||
Theory: How to build Android application having C++ native part (from command line)
|
||||
@@ -103,11 +106,11 @@ Here is the standard way to compile C++ part of an Android application:
|
||||
|
||||
<path_where_NDK_is_placed>/ndk-build
|
||||
|
||||
.. note:: If you are working in *cygwin* shell and encounter an error saying that NDK does not find some *cygwin*\ 's path then you might need to define the following environment variable:
|
||||
.. note:: On Windows we recomend use of ``ndk-build.cmd`` in standard Windows console (``cmd.exe``) rather than the similar ``bash`` script in ``Cygwin`` shell.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
export NDK_USE_CYGPATH=1
|
||||
.. image:: images/ndk_build.png
|
||||
:alt: NDK build
|
||||
:align: center
|
||||
|
||||
#. After executing this command the C++ part of the source code is compiled.
|
||||
|
||||
@@ -134,95 +137,66 @@ After that the Java part of the application can be (re)compiled (using either *E
|
||||
Theory: How to build Android application having C++ native part (from *Eclipse*)
|
||||
================================================================================
|
||||
|
||||
There are several possible ways to integrate compilation of C++ code by Android NDK into Eclipse compilation process. We recommend the approach taken from this site: http://mobilepearls.com/labs/ndk-builder-in-eclipse/
|
||||
There are several possible ways to integrate compilation of C++ code by Android NDK into Eclipse compilation process.
|
||||
We recommend the approach based on Eclipse :abbr:`CDT(C/C++ Development Tooling)` Builder.
|
||||
|
||||
.. important:: This instructions should be applied for each Android project in *Eclipse* workspace. So if you have 3 projects having C++ part then you need to configure 3 builders.
|
||||
.. important:: Make sure your Eclipse IDE has the :abbr:`CDT(C/C++ Development Tooling)` plugin installed. (Menu ``Help`` -> ``About Eclipse SDK`` -> ``Installation Details``)
|
||||
|
||||
Below is an adapted version of this guide:
|
||||
.. image:: images/eclipse_inst_details.png
|
||||
:alt: Configure builders
|
||||
:align: center
|
||||
|
||||
#. Navigate to :guilabel:`Package Explorer` window and expand your project having JNI resources.
|
||||
To install the `CDT plugin <http://eclipse.org/cdt/>`_ use menu ``Help`` -> ``Install New Software...``,
|
||||
then paste the CDT 8.0 repository URL http://download.eclipse.org/tools/cdt/releases/indigo as shown on the picture below and click :guilabel:`Add...`, name it *CDT* and click :guilabel:`OK`.
|
||||
|
||||
.. image:: images/eclipse_inst_cdt.png
|
||||
:alt: Configure builders
|
||||
:align: center
|
||||
|
||||
If you can not see :file:`libs` folder under this project then you need to create it manually. (It will be required on step 7, but you need to create it before you open project properties.)
|
||||
``CDT Main Features`` should be enough:
|
||||
|
||||
.. image:: images/eclipse_inst_cdt_2.png
|
||||
:alt: Configure builders
|
||||
:align: center
|
||||
.. important:: This instructions should be applied for each Android project in *Eclipse* workspace having native (JNI) part to build.
|
||||
|
||||
#. Right click on your project in :guilabel:`Package Explorer` window and select :guilabel:`Properties`.
|
||||
#. Right click on your project in :guilabel:`Package Explorer` window and select :guilabel:`New` -> :guilabel:`Other`:
|
||||
|
||||
#. In the :guilabel:`Properties` dialog select :guilabel:`Builders` menu and press the :guilabel:`New...` button:
|
||||
|
||||
.. image:: images/eclipse_builders.png
|
||||
:alt: Configure builders
|
||||
.. image:: images/eclipse_cdt_cfg1.png
|
||||
:alt: Configure CDT
|
||||
:align: center
|
||||
|
||||
#. In the resulting dialog select the :guilabel:`Program` type and press :guilabel:`OK` button:
|
||||
#. Select :guilabel:`C/C++` -> :guilabel:`Convert to C/C++ project`:
|
||||
|
||||
.. image:: images/eclipse_builder_types.png
|
||||
:alt: Choose builder type
|
||||
.. image:: images/eclipse_cdt_cfg2.png
|
||||
:alt: Configure CDT
|
||||
:align: center
|
||||
|
||||
#. In the :guilabel:`Main` tab fill the following fields:
|
||||
#. Select :guilabel:`"C++"`, :guilabel:`"Makefile Project"`, :guilabel:`"Other Toolchain"`:
|
||||
|
||||
* :guilabel:`Name` - any name for your builder. ("Tutorial 2.1 Builder" in my case.)
|
||||
.. image:: images/eclipse_cdt_cfg3.png
|
||||
:alt: Configure CDT
|
||||
:align: center
|
||||
|
||||
.. note:: This name has to be unique for each project in your workspace.
|
||||
#. Right click on your project in :guilabel:`Package Explorer` window and select :guilabel:`Properties`, then :guilabel:`C/C++ Build` in the left pane.
|
||||
Unckeck :guilabel:`Use default build command` and put ``ndk-build`` invocation in the :guilabel:`Build command` edit box and click :guilabel:`Apply` :
|
||||
|
||||
* :guilabel:`Location` - full path to :command:`ndk-build` tool.
|
||||
.. image:: images/eclipse_cdt_cfg4.png
|
||||
:alt: Configure CDT
|
||||
:align: center
|
||||
|
||||
+ *UNIX*
|
||||
#. Select :guilabel:`Builders` in the left pane, select :guilabel:`"CDT Builder"`, press :guilabel:`Edit` button on the righ and set check-boxes as on the picture below for automatic rebuild of JNI part:
|
||||
|
||||
Just put full path to :command:`ndk-build` into this filed. Also you can add some options to the :guilabel:`Arguments:guilabel:` fied, for example ``-B`` option.
|
||||
.. image:: images/eclipse_cdt_cfg5.png
|
||||
:alt: Configure CDT
|
||||
:align: center
|
||||
|
||||
+ *Cygwin*
|
||||
|
||||
- Instead of path to the :command:`ndk-build` tool you need to put full path to *cygwin*\ 's :program:`bash.exe` location. E.g: :file:`C:\\cygwin\\bin\\bash.exe`.
|
||||
#. Use menu :guilabel:`Project` -> :guilabel:`Clean...` to make sure that NDK build is invoked on the project build:
|
||||
|
||||
- Put full path to :command:`ndk-build` into the :guilabel:`Arguments` field E.g. :file:`C:\\Android\\android-ndk-r6\\ndk-build`.
|
||||
|
||||
- Go to the :guilabel:`Environment` tab and define an environment variable:
|
||||
|
||||
* :envvar:`PATH` - full path to the *cygwin* tools. E.g. :file:`C:\\cygwin\\bin`
|
||||
|
||||
.. image:: images/eclipse_windows_environment.png
|
||||
:alt: Define environment variables
|
||||
:align: center
|
||||
|
||||
* :guilabel:`Working Directory` - put path to your project into this field. Instead of hardcoding full path you can click :guilabel:`Browse Workspace...` button and select your project.
|
||||
|
||||
.. image:: images/eclipse_edit_configuration_main.png
|
||||
:alt: Define environment variables
|
||||
:align: center
|
||||
|
||||
#. Go to the :guilabel:`Refresh` tab and select both :guilabel:`Refresh resources upon completion` and :guilabel:`Recursively include sub-folders`.
|
||||
|
||||
Next set the :guilabel:`Specific resources` option and click :guilabel:`Specify resources...` button:
|
||||
|
||||
.. image:: images/eclipse_edit_configuration_refresh.png
|
||||
:alt: Define environment variables
|
||||
:align: center
|
||||
|
||||
#. Select :file:`libs` folder under your project and click :guilabel:`Finish`:
|
||||
|
||||
.. image:: images/eclipse_edit_configuration_specify_resources.png
|
||||
:alt: Select resources folder to refresh automatically
|
||||
:align: center
|
||||
|
||||
#. Go to the last tab :guilabel:`Build options`. Make sure that all checkboxes are set as shown on the next screen:
|
||||
|
||||
.. image:: images/eclipse_edit_configuration_build_options.png
|
||||
:alt: Configure build options
|
||||
:align: center
|
||||
|
||||
#. Next, click the :guilabel:`Specify resources...` button.
|
||||
|
||||
#. Select :file:`jni` folder of your project and click the :guilabel:`Finish` button:
|
||||
|
||||
.. image:: images/eclipse_edit_configuration_build_resources.png
|
||||
:alt: Select resources to build
|
||||
:align: center
|
||||
|
||||
#. Finally press :guilabel:`OK` in the builder configuration and project properties dialogs. If you have automatic build turned on then console showing build log should appear:
|
||||
|
||||
.. image:: images/eclipse_NDK_build_success.png
|
||||
:alt: Select resources to build
|
||||
:align: center
|
||||
.. image:: images/eclipse_ndk_build.png
|
||||
:alt: Select resources folder to refresh automatically
|
||||
:align: center
|
||||
|
||||
Theory: The structure of :file:`Android.mk` and :file:`Application.mk` scripts
|
||||
==============================================================================
|
||||
@@ -255,65 +229,30 @@ Usually the file :file:`Application.mk` is optional, but in case of project usin
|
||||
Practice: Build samples from OpenCV binary package
|
||||
==================================================
|
||||
|
||||
OpenCV binary package includes two samples having JNI resources:
|
||||
OpenCV binary package includes 3 samples having JNI resources:
|
||||
|
||||
* *Tutorial 2 Advanced - 1. Add Native OpenCV*
|
||||
* *Tutorial 3 (Advanced) - Add Native OpenCV*
|
||||
|
||||
This sample illustrate how you can use OpenCV in C++ but without OpenCV Java API.
|
||||
This sample illustrates how you can use OpenCV in C++ but without OpenCV Java API.
|
||||
|
||||
* *Tutorial 2 Advanced - 2. Mix Java+Native OpenCV*
|
||||
* *Tutorial 4 (Advanced) - Mix Java+Native OpenCV*
|
||||
|
||||
This sample shows how you can mix OpenCV Java API and native C++ code.
|
||||
|
||||
To build these samples you need to:
|
||||
|
||||
#. Fulfill all the steps, described in the tutorial :ref:`Android_Binary_Package`.
|
||||
|
||||
#. Setup one builder for *"Tutorial 2 Advanced - 1. Add Native OpenCV"* project (as described in :ref:`Android_NDK_integration_with_Eclipse`)
|
||||
|
||||
#. Setup second builder for *"Tutorial 2 Advanced - 2. Mix Java+Native OpenCV"* project (repeat the steps from :ref:`Android_NDK_integration_with_Eclipse`)
|
||||
|
||||
#. Clean these projects (in the main Eclipse menu: :menuselection:`Project --> Clean...`)
|
||||
|
||||
#. Run Eclipse build command (if option :guilabel:`Build Automatically` is not set)
|
||||
* *Sample - face-detection*
|
||||
|
||||
This sample illustrates usage of both simple OpenCV face detector via Java API and advanced detection based face tracker via JNI and C++.
|
||||
|
||||
Before OpenCV 2.4.2 for Android these projects are not configured to use CDT for building their native part , so you can do it yourself.
|
||||
|
||||
Practice: Create an Android application, which uses OpenCV
|
||||
==========================================================
|
||||
|
||||
To build your own Android application, which uses OpenCV from native part, the following steps should be done:
|
||||
|
||||
#. The archive with OpenCV binary package should be downloaded and extracted to some folder (as example, into the home folder)
|
||||
#. The archive with OpenCV binary package should be downloaded and extracted to some folder (e.g. ``C:\Work\android-opencv\OpenCV-2.4.0``)
|
||||
|
||||
#. We recommend to use an environment variable to specify the location of OpenCV package. Full or relative path hardcoded in :file:`jni/Android.mk` will also work.
|
||||
|
||||
So, the environment variable :envvar:`OPENCV_PACKAGE_DIR` should be defined.
|
||||
The value of the variable should points to the folder, where the OpenCV package has been extracted.
|
||||
|
||||
|
||||
As an example, on *UNIX* you can add add the following line into the hidden file :file:`.bashrc` placed in your home folder:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
export OPENCV_PACKAGE_DIR = <path to the extracted OpenCV package>
|
||||
|
||||
Then relogin (or better reboot your computer).
|
||||
|
||||
.. attention:: without rebooting (or logout) this change might not work.
|
||||
|
||||
If you are a *Windows* user, then navigate to:
|
||||
|
||||
* *Windows 7 / Windows Vista*
|
||||
|
||||
:menuselection:`My Computer (Right Click on Icon) --> Properties (Link) --> Advanced System Settings (Link) --> Advanced (Tab) --> Environment Variables (Button) --> System variables (Section)`
|
||||
|
||||
* *Windows XP*
|
||||
|
||||
:menuselection:`My Computer (Right Click on Icon) --> Properties (Link) --> Advanced (Tab) --> Environment Variables (Button) --> System variables (Section)`
|
||||
|
||||
Create new variable :envvar:`OPENCV_PACKAGE_DIR` and similarly to *UNIX* relogin or reboot.
|
||||
|
||||
If you are setting NDK builder as described above in :ref:`Android_NDK_integration_with_Eclipse`, then you can define this variable in builder settings. It can be done on third :guilabel:`Environment` tab of the builder configuration window (we have already added some variables to this tab on *Windows* but skipped it for other platforms).
|
||||
#. You can use an environment variable to specify the location of OpenCV package or just hardcode full or relative path in the :file:`jni/Android.mk` of your projects.
|
||||
|
||||
#. The file :file:`jni/Android.mk` should be written for the current application using the common rules for the file.
|
||||
|
||||
@@ -324,7 +263,7 @@ To build your own Android application, which uses OpenCV from native part, the f
|
||||
|
||||
.. code-block:: make
|
||||
|
||||
include $(OPENCV_PACKAGE_DIR)/share/OpenCV/OpenCV.mk
|
||||
include C:\Work\android-opencv\OpenCV-2.4.0\share\OpenCV\OpenCV.mk
|
||||
|
||||
should be inserted into the :file:`jni/Android.mk` file right after the line
|
||||
|
||||
@@ -332,11 +271,25 @@ To build your own Android application, which uses OpenCV from native part, the f
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
.. note:: If your application utilize both native (C++) OpenCV and its Java API you need to put the following line before including :file:`OpenCV.mk` to avoid conflict between C++ and Java builders:
|
||||
Several variables can be used to customize OpenCV stuff, they should be set **before** the ``"include ...\OpenCV.mk"`` line:
|
||||
|
||||
.. code-block:: make
|
||||
.. code-block:: make
|
||||
|
||||
OPENCV_CAMERA_MODULES:=off
|
||||
OPENCV_INSTALL_MODULES:=on
|
||||
|
||||
Copies necessary OpenCV dynamic libs to the project ``libs`` folder in order to include them into the APK.
|
||||
|
||||
.. code-block:: make
|
||||
|
||||
OPENCV_CAMERA_MODULES:=off
|
||||
|
||||
Skip native OpenCV camera related libs copying to the project ``libs`` folder.
|
||||
|
||||
.. code-block:: make
|
||||
|
||||
OPENCV_LIB_TYPE:=STATIC
|
||||
|
||||
Perform static link with OpenCV. By default dynamic link is used and the project JNI lib depends on ``libopencv_java.so``.
|
||||
|
||||
#. The file :file:`Application.mk` should exist and should contain lines
|
||||
|
||||
@@ -353,25 +306,4 @@ To build your own Android application, which uses OpenCV from native part, the f
|
||||
|
||||
is recommended for the applications targeting modern ARMs
|
||||
|
||||
#. To build the C++ code the Android NDK script :command:`ndk-build` should be run in the root directory of application.
|
||||
Then the C++ source code using OpenCV will be built by Android NDK build system.
|
||||
After that the Java part of the application can be rebuild and the application can be installed on an Android device.
|
||||
|
||||
Note that this step requires calling the :command:`ndk-build` script from the console. Instead of this step you can use integration of Android NDK into Eclipse
|
||||
as stated above in the section :ref:`Android_NDK_integration_with_Eclipse` .
|
||||
|
||||
|
||||
Additional C++ support in Eclipse
|
||||
==================================
|
||||
|
||||
Note that you can install additional C++ plugins in Eclipse:
|
||||
|
||||
#. Open :guilabel:`Help / Install New Software`. This shows the :guilabel:`Install` dialog.
|
||||
|
||||
#. In the :guilabel:`Work with` drop-down list choose :guilabel:`Helios - http://download.eclipse.org/releases/helios` (or :guilabel:`Indigo - http://download.eclipse.org/releases/indigo` depending on your Eclipse version) and wait while the list of available software is loaded.
|
||||
|
||||
#. From the list of available software select :menuselection:`Programming Languages --> C/C++ Development Tools`.
|
||||
|
||||
#. Click :guilabel:`Next`, click :guilabel:`Next` again, accept the agreement, and click the :guilabel:`Finish` button.
|
||||
|
||||
#. When installation is finished, click :guilabel:`Reload`
|
||||
#. Either use :ref:`manual <NDK_build_cli>` ``ndk-build`` invocation or :ref:`setup Eclipse CDT Builder <Android_NDK_integration_with_Eclipse>` to build native JNI lib before Java part [re]build and APK creation.
|
||||
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 73 KiB |
After Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 91 KiB |
After Width: | Height: | Size: 91 KiB |
After Width: | Height: | Size: 94 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 73 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 37 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 14 KiB |