Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Accessing OpenCV functions

David Miguel Lozano edited this page Oct 1, 2016 · 1 revision

Android supports two main methods for application development: in Java using the Android SDK, and in C/C++ using the Android Native Development Kit (NDK). It is also possible to combine these two modes in a single application. Analogously, there are two ways to access functions from the OpenCV libraries in Android: through its native API and its Java API.

Native

Intrinsically, the OpenCV libraries are compiled in native form (C/C++), which can be called in Android native applications/libraries. The native user libraries can, in turn, be accessed from Java through the Java Native Interface (JNI).

Java

The other method for accessing OpenCV functions is through its Java API. In addition to their C/C++ interface, there are Java wrappers for most of the OpenCV functions. These can be accessed directly by Android applications in Java.

Note, however, that even for calls to OpenCV functions through their Java interface, all computations are internally performed at the native level. Hence the overhead of a call to an OpenCV function through its Java interface is equal to the cost of one or several JNI calls.

The following illustration presents the software stacks for Android applications that use OpenCV:

OpenCV stack

There are pros and cons to both approaches of using OpenCV for Tegra in Android application. Using native calls can result in fewer overheads for JNI calls, but requires more programming effort. Conversely, using the Java interface requires less programming effort, but the overhead of JNI calls can quickly add up if many calls to individual OpenCV functions are made.

Note: If, in an application, you anticipate processing an image/video frame with a number of consecutive computer vision functions, it might be advantageous to write one native C/C++ library that calls all these functions. This native library can be accessed by the Android application via one JNI call per frame.

References