OpenCV  4.1.0
Open Source Computer Vision
OpenCV4Android SDK

This tutorial was designed to help you with installation and configuration of OpenCV4Android SDK.

This guide was written with MS Windows 7 in mind, though it should work with GNU Linux and Apple Mac OS as well.

This tutorial assumes you have the following software installed and configured:

If you need help with anything of the above, you may refer to our Introduction into Android Development guide.

If you encounter any error after thoroughly following these steps, feel free to contact us via OpenCV4Android discussion group or OpenCV Q&A forum. We'll do our best to help you out.

General info

OpenCV4Android SDK package enables development of Android applications with use of OpenCV library.

The structure of package contents looks as follows:

OpenCV-2.4.9-android-sdk
|_ apk
|   |_ OpenCV_2.4.9_binary_pack_armv7a.apk
|   |_ OpenCV_2.4.9_Manager_2.18_XXX.apk
|
|_ doc
|_ samples
|_ sdk
|    |_ etc
|    |_ java
|    |_ native
|          |_ 3rdparty
|          |_ jni
|          |_ libs
|               |_ armeabi
|               |_ armeabi-v7a
|               |_ x86
|
|_ LICENSE
|_ README.android
Note
Installation from Internet is the preferable way since OpenCV team may publish updated versions of this packages on the Market.

Starting from version 2.4.3 OpenCV4Android SDK uses OpenCV Manager API for library initialization. OpenCV Manager is an Android service based solution providing the following benefits for OpenCV applications developers:

Manual OpenCV4Android SDK setup

Get the OpenCV4Android SDK

  1. Go to the OpenCV download page on SourceForge and download the latest available version. This tutorial is based on this package: OpenCV-2.4.9-android-sdk.zip.
  2. Create a new folder for Android with OpenCV development. For this tutorial we have unpacked OpenCV SDK to the C:\Work\OpenCV4Android\ directory.
Note
Better to use a path without spaces in it. Otherwise you may have problems with ndk-build.
  1. Unpack the SDK archive into the chosen directory.

    You can unpack it using any popular archiver (e.g with 7-Zip):

    android_package_7zip.png

    On Unix you can use the following command:

    unzip ~/Downloads/OpenCV-2.4.9-android-sdk.zip

Import OpenCV library and samples to the Eclipse

  1. Start Eclipse and choose your workspace location.

    We recommend to start working with OpenCV for Android from a new clean workspace. A new Eclipse workspace can for example be created in the folder where you have unpacked OpenCV4Android SDK package:

    eclipse_1_choose_workspace.png
  1. Import OpenCV library and samples into workspace.

    OpenCV library is packed as a ready-for-use Android Library Project. You can simply reference it in your projects.

    Each sample included into the OpenCV-2.4.9-android-sdk.zip is a regular Android project that already references OpenCV library. Follow the steps below to import OpenCV and samples into the workspace:

    • Right click on the Package Explorer window and choose Import... option from the context menu:

      eclipse_5_import_command.png
    • In the main panel select General –> Existing Projects into Workspace and press Next button:

      eclipse_6_import_existing_projects.png
    • In the Select root directory field locate your OpenCV package folder. Eclipse should automatically locate OpenCV library and samples:

      eclipse_7_select_projects.png
    • Click Finish button to complete the import operation.
Note
OpenCV samples are indeed dependent on OpenCV library project so don't forget to import it to your workspace as well.
After clicking Finish button Eclipse will load all selected projects into workspace, and you
have to wait some time while it is building OpenCV samples. Just give a minute to Eclipse to
complete initialization.

![](images/eclipse_cdt_cfg4.png)

Once Eclipse completes build you will have the clean workspace without any build errors:

![](images/eclipse_10_crystal_clean.png)

Running OpenCV Samples

At this point you should be able to build and run the samples. Keep in mind, that face-detection and Tutorial 2 - Mixed Processing include some native code and require Android NDK and NDK/CDT plugin for Eclipse to build working applications. If you haven't installed these tools, see the corresponding section of Introduction into Android Development.

warning

Please consider that some samples use Android Java Camera API, which is accessible with an AVD.

Note
Recent *Android SDK tools, revision 19+* can run ARM v7a OS images but they available not for all Android versions.

Well, running samples from Eclipse is very simple:

Note
Android Emulator can take several minutes to start. So, please, be patient. * On the first run Eclipse will ask you about the running mode for your application:
eclipse_11_run_as.png
Note
armeabi, armv7a-neon, arm7a-neon-android8, mips and x86 stand for platform targets:
  • armeabi is for ARM v5 and ARM v6 architectures with Android API 8+,
  • armv7a-neon is for NEON-optimized ARM v7 with Android API 9+,
  • arm7a-neon-android8 is for NEON-optimized ARM v7 with Android API 8,
  • mips is for MIPS architecture with Android API 9+,
  • x86 is for Intel x86 CPUs with Android API 9+.
If using hardware device for testing/debugging, run the following command to learn its CPU architecture:
adb shell getprop ro.product.cpu.abi
If you're using an AVD emulator, go Window > AVD Manager to see the list of available devices. Click Edit in the context menu of the selected device. In the window, which then pop-ups, find the CPU field.
You may also see section Manager Selection for details.

When done, you will be able to run OpenCV samples on your device/emulator seamlessly.

What's next

Now, when you have your instance of OpenCV4Adroid SDK set up and configured, you may want to proceed to using OpenCV in your own application. You can learn how to do that in a separate Android Development with OpenCV tutorial.