Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do we need the NDK for OpenCV Android

I am just starting to learn OpenCV for Android, I have played around with it a bit and it all works fine.

I installed the NDK and managed to run some of the sample apps which included it.

I am not clear on what we need the NDK for. I could not find it referenced anywhere in the documentation.

Is there OpenCV functionality which is not available in the regular library 2.4.8 ?

Is it just so we can use modules written in c++ that others have made available, without rewriting them in java ?

like image 536
Ryan Heitner Avatar asked Jan 08 '14 13:01

Ryan Heitner


People also ask

Why do we need android NDK?

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.

Is NDK necessary for Android Studio?

But even if we know C or C++, how would we implement it in our app? So this is where we require NDK to integrate the native-code languages to make it run on the app. Let's see some more advantages of using NDK: It provides a way to embed the equivalent native libraries in the apk.

What is difference between android NDK and sdk?

Android provides Native Development Kit (NDK) to support native development in C/C++, besides the Android Software Development Kit (Android SDK) which supports Java. [TODO] more. NDK is a complex and advanced topics.


2 Answers

I have been using NDK for my application and following are my observations.

  1. Yes, it gives the advantage of using plenty of c++ modules which are made available.
  2. If you already have a bit of experience in computer vision application programming using openCV library in C++, you don´t have to learn new syntaxes in java(can be quite irritating some times).
  3. Using NDK for your app can give you a slight upperhand in terms of
    performance when image processing you do is computationally demanding (I am not quite sure about this because the openCV library made available for Android is just a wrapper around the same header files and stuff and should almost give the same performance as NDK. I have never really compared the performance myself but have read in various blogs that NDK is faster).
  4. One thing you really have to be careful when using NDK is calls from JAVA to NDK side or the other way round, these calls can be really expensive in terms of performance(Needs careful planning).
  5. Passing few parameters like array of MAT from JAVA to NDK are a bit of headache, but you can find few workarounds.

Based on these and other factors you might have found out from various sources and also by your programming strengths you can decide if you want to use NDK or not. There was never really a set of guidelines i could find that says you can use NDK if so and so conditions are satisfied, people just start with which ever programming style they are more comfortable with.

like image 105
Darshan Avatar answered Nov 14 '22 23:11

Darshan


In Android documentation they advice to use NDK in case of

# CPU-intensive operations that don't allocate much memory,
# such as signal processing, physics simulation, and so on.

If everything you want to do can be computed with OpenCV built'in functions, you may not need NDK as processing routines of OpenCV are already in C/C++.

However, if you have to process the images matrix intensively (I mean direct access to pixels), you will improve performances using the NDK.

like image 31
leadrien Avatar answered Nov 15 '22 01:11

leadrien