Click here to Skip to main content
15,868,016 members
Articles / Mobile Apps / Android
Article

Getting Started with Intel® INDE OpenCV for Android Targets

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
6 Jul 2015CPOL7 min read 9.2K   5  
This document is focused on creating OpenCV-enabled applications for Android. If the target operating system of your application is Windows

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

Intel® Developer Zone offers tools and how-to information for cross-platform app development, platform and technology information, code samples, and peer expertise to help developers innovate and succeed. Join our communities for Android, Internet of Things, Intel® RealSense™ Technology and Windows to download tools, access dev kits, share ideas with like-minded developers, and participate in hackathon’s, contests, roadshows, and local events.

About Intel INDE OpenCV

The Intel® Integrated Native Developer Experience (Intel® INDE) is a cross-architecture productivity suite that provides developers with tools, support, and IDE integration to create high-performance C++/Java* applications for Windows* on Intel® architecture and Android* on ARM* and Intel® architecture.

The new OpenCV beta, a feature of Intel INDE, is compatible with the new open source OpenCV 3.0 beta (Open Source Computer Vision Library: http://opencv.org). OpenCV beta provides free binaries for computer vision applications development and production for usages like enhanced photography, augmented reality, video summarization, and more.

Key features of the Intel® INDE OpenCV are:

  • Compatibly with OpenCV 3.0
  • Pre-build and validated binaries, cleared of IP protected building blocks.
  • Easy-to-use and to maintain with IDE integration for both Windows and Android development.
  • Optimized for Intel® platforms with heterogeneous computing.

This document is focused on creating OpenCV-enabled applications for Android*. If the target operating system of your application is Windows*, refer to the Getting Started with Intel’s INDE OpenCV for Windows*.

Installation Guide for Intel INDE OpenCV for Android* Targets

Refer to the Quick Installation Guide for Intel® INDE OpenCV for installation details.

Intel INDE OpenCV Android* Support Is BETA

The community version of OpenCV 3.0 Beta does not offer Android support. Intel INDE OpenCV provides preview Android 32-bit binaries. At the time of this release, the community OpenCV 3.0 API is not finalized (still Beta). Similarly, for the Intel INDE OpenCV binaries for Android* targets, the APIs are not final, and you can expect minor API changes over time.

Some OpenCV 3.0 Features Are Limited to JNI on Android*

Notice that for the Beta release, some important OpenCV 3.0 features on Android* are limited to JNI only. JNI stands for Java Native Interface - an application development approach with the C/C++ code communicating with the rest of Java via JNI.

For example, UMat support is available only in the native C++ code, and not available through the OpenCV Java API. For details refer to the OpenCV 3.0 Architecture Guide for Intel INDE OpenCV.

Still the Intel INDE OpenCV preview binaries for Android* enable you to start developing and testing applications for Android* targets.

Components of the Intel INDE OpenCV for Android Targets

Intel INDE OpenCV contains the following components for Android* targets:

  • Ready-to-use binaries for Android* application development (x86)
  • Intel INDE OpenCV version of the OpenCV4Android
  • Integration into Eclipse* and Android Studio* IDEs

Intel INDE OpenCV Android*-related files structure is as follows:

<Intel-OpenCV root dir> (e.g. C:\Intel\INDE\OpenCV)
|_sdk             - INDE OpenCV "root" folder for Android (x86)
 |_aar            - binary distribution of the INDE OpenCV library (for Android Studio*) 
 |_etc            - classifiers data for object detection functions (in xml)
 |_java           - root folder for INDE OpenCV Android (Java)    
   |_3rdparty     - 3rd party components libs (like libtiff, libjpeg, etc)
   |_libs         - static (".a") and dynamic (".so") libraries INDE OpenCV
   |_res          - resource files (strings, icons, etc) for INDE OpenCV
   |_src          - INDE OpenCV Java and application helper classes    
 |_native         - root folder for Native INDE OpenCV for Android (for C/C++ dev)   
   |_3rdparty     - 3rd party components (like libtiff, libjpeg, etc)
   |_jni          - Native Interface for INDE OpenCV
     |_include    - header files for INDE OpenCV
   |_libs         - static (".a") and dynamic (".so") libraries INDE OpenCV

Intel INDE OpenCV: Alternative to the Android* OpenCV Manager

Android* OpenCV Manager (http://docs.opencv.org/platforms/android/service/doc/index.html) is a service that manages OpenCV library binaries on the end-user devices. The service uses a mechanism of constants (tags) to differentiate OpenCV versions, which is explained in the OpenCV docs as well.

You can switch your application to use the Intel INDE OpenCV version. Intel INDE OpenCV binaries are not available via the Android OpenCV Manager. To enable Intel INDE OpenCV binaries support in your application, provide a specific tag (see the code example below) to the regular initAsync() call. Otherwise the application uses the community OpenCV libraries by default.

This chapter is relevant to the existing OpenCV-enabled application that use the Android OpenCV Manager via the initAsync() method of the Java OpenCV Loader. With the Intel INDE OpenCV, you should use this function even though the binaries are actually loaded from the application’s *.apk file. Applications created with the Intel INDE OpenCV Android Studio* and Eclipse* wizards use this method by default.

Notice that Intel INDE OpenCV binaries should be explicitly packaged into the resulting *.apk for your application. The ways to pack the binaries are described in the IDE-specific chapters of this article.

General machinery of the actual binaries loading and associated callbacks are explained in http://docs.opencv.org/platforms/android/service/doc/index.html. The only specific of Intel INDE OpenCV is a dedicated versioning constant. Consider the following code example (error handling is omitted for clarity):

C#
public void onResume()
{
   super.onResume();
       // load INDE OpenCV binaries right from the apk using the specific tag
       if(!OpenCVLoader.initAsync(
           OpenCVLoader.OPENCV_INTEL_INDE_VERSION_3_0_0_PREVIEW,
           this, mLoaderCallback))
       {
           //if failed, report error and exit
       }
}

Applications, created with the Intel INDE OpenCV wizards for Android Studio* and Eclipse* use the correct tag by default.

Creating OpenCV-Enabled Applications Using Intel INDE OpenCV IDE Wizards

Intel INDE is a turnkey development suite for Android. Upon Intel INDE installation, Intel INDE OpenCV enables you to develop computer vision applications with Eclipse* and Android Studio* IDEs.

Refer to the Quick Installation Guide for Intel INDE OpenCV for installation details per IDE.

Android Studio* Support with Intel INDE OpenCV: Creating New Project

Intel INDE OpenCV provides Java and JNI project wizards for Android Studio*. JNI stands for Java Native Interface. It is an application development approach with the C/C++ code communicating with the rest of Java via JNI. According to the JNI approach, your code uses Intel INDE OpenCV directly in C/C++, just like any other native library.

To create any type of application,

  1. Start with a regular Create New Project wizard (Ctrl-N).
  2. In the Configure your new project step, specify the Application name, project location, and so on:Image 1
  3. In the Select the form factors your app will run on, select Phone and Tablet and specify the API Level 19 to match general Intel INDE requirements:Image 2

  4. Select either (pure Java) Intel INDE OpenCV Project or Intel INDE OpenCV JNI Project:Image 3

  5. Finally, specify the Activity Name, Layout Name, Title, Main Resource Name for the new project activity:Image 4

  6. Click Finish and start working with your first Intel INDE OpenCV project in the Android Studio*:Image 5

 

We generally recommend to start with JNI projects ("Intel INDE OpenCV Android Project" wizard). To edit the JNI files, navigate to the "<your_project_dir>/jni" folder directly.

Android Studio Support with Intel INDE OpenCV: Enable an Existing Project

To enable Intel INDE OpenCV support for an existing project, patch the build.gradle file for each module where you use Intel INDE OpenCV:

Image 6

Depending on whether you are going to use Intel INDE OpenCV via its Java interface or via JNI support, slightly different patches should be applied to the build.gradle file for your module. Specifically, use different AAR files.

If your module uses pure Java OpenCV interface and you don’t have any native OpenCV code built with NDK, the following snippet should be added into the end of module’s build.gradle file:

Java
repositories {
    flatDir {
        dirs System.getenv("INDE_OPENCV_AAR_DIR")
    }
}
dependencies {
    compile(name: 'openCVLibrary300intelJava', ext: 'aar')
}

For the JNI project, re-create activity with help of the Intel INDE OpenCV JNI Project template instead of enabling an existing module with the Intel INDE OpenCV support. If using the template is not acceptable, do the following:

  1. Patch the build.gradle file with the following code (no Java suffix in the name of AAR file):

    Java
    repositories {
        flatDir {
            dirs System.getenv("INDE_OPENCV_AAR_DIR")
        }
    }
    dependencies {
        compile(name: 'openCVLibrary300intel', ext: 'aar')
    }

    In the Android.mk file, add the following line right after the include $(CLEAR_VARS) line:

    include $(INDE_OPENCV_DIR)\sdk\native\jni\OpenCV.mk
  2. Make sure that APP_STL := gnustl_shared is used in the Application.mk file to be compatible with the Intel INDE OpenCV binaries. Using other types of the runtime library may lead to undefined behavior during application execution.

Eclipse* Support with Intel INDE OpenCV: Creating A New Project

Intel INDE OpenCV provides an Eclipse* project wizard for creating Android* applications. To create a new project with Intel INDE OpenCV support, select File > New > Project (Ctrl -N).

Select OpenCV Project from the list of projects and enter name and location for the new project in the next wizard page:
Image 7Image 8

Once finished, click Finish.

Now both the new project and Intel INDE OpenCV library project are imported and opened in Eclipse*, with the project’s dependencies and Java build paths resolved accordingly. So just start coding!

Image 9

If you are willing to develop OpenCV-enabled applications using JNI, refer to the Android Studio* instead (previous section).

Eclipse* Support with Intel INDE OpenCV: Enable an Existing Project

To enable Intel INDE OpenCV for an existing Android* (Java) project, right-click your project in the Package Explorer view in Eclipse* and select Enable OpenCV support:

Image 10

Using this command, you import the Intel INDE OpenCV library into your workspace and set dependencies to the Intel INDE OpenCV for your project:

Image 11

Note on Development for Android* Targets with Microsoft Visual Studio*

Notice that in the current release, Visual Studio is not supported for Android* development with Intel INDE OpenCV. Please select other IDEs like Android Studio or Eclipse during the installation. Refer to the Quick Installation of Intel® INDE-OpenCV for the installation details.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
Intel is inside more and more Android devices, and we have tools and resources to make your app development faster and easier.


Comments and Discussions

 
-- There are no messages in this forum --