1

I've seen 2 ways of using OpenCV in Android devices:

  1. with Java OpenCV API
  2. with C++ OpenCV API

My question is: which one is better, faster, more easy to configure/code? Or, if my question is wrong, what are the pros and cons for each way? I read OpenCV documentation and several articles, but couldn't find the answer for my question.

3 Answers 3

1

I guess it has to do more about your application’s implementation. Is it a java or a c++ (native) application? Is image processing an important load of your application? Do you need computing speed or implementation speed? Anyway, I’ve used OpenCV (C++ implementation) in java via the JNI and the NDK. The core of my application is image processing and processing speed is very much in my interest (almost real-time). Everything is written in C++, as I have both desktop and mobile implementations of my imaging system.

In the mobile application (for android), my imaging system is embedded in a java application. From here, I see processing split into two parts: Image acquisition (via the device camera) and image processing (via OpenCV). Image acquisition is all made in java. The work wasn’t trivial, as the main problem I found was acquiring RGB frames from the camera (natively YUV), passing them to OpenCV, receiving results from OpenCV and rendering them to the application’s surfaceview.

Interfacing the camera and OpenCV can be a headache indeed, depending mainly on your device capabilities and your SDKs versions. After acquiring the image, processing was relatively painless. All my system was previously debugged on my PC and I knew exactly what to expect. All OpenCV functions behaved as they should, so I had almost no problems with this part.

I had also spent a lot of time working in C++, so that was a factor in deciding what kind of implementation to choose. Now, the application is pretty much setup. I can add new features and test them in my PC and update the mobile port rather quickly.

Sign up to request clarification or add additional context in comments.

2 Comments

Since I did not start my project yet, anything (Java API or C++ API) is okay. Thus, I wanna know pros and cones of both. Your reply is indeed very helpful, but not exact answer for my question. Thank you anyway - @eldesgraciado :)
@Sherzod No problem, mate. If you are going for speed, then consider implementing your OpenCV system in C++. Be aware that the Java-C++ interface can get a little bit nasty, so also consider the debugging tools you have at your disposal. Just my two cents from experience. Hopefully, you will be able to find a more concrete answer to your questions. Cheers!
1

The OpenCV Java API is the standard way of using OpenCV with Android. It's basically a Java layer on top of the C++ API, where each OpenCV Java function is calling its C++ equivalent through JNI (Java Native Interface).

Making a JNI call induces a small overhead, increasing the execution time of your OpenCV function when using the Java API. If your image processing pipeline is making a lot of calls to OpenCV functions (let's say N calls), then the JNI calls overhead will affect N times your pipeline, which can slow down your total computation time.

An alternative is to implement your entire image processing pipeline in C++ and call that C++ code from Java, reducing the overhead to only one JNI call.

OpenCV C++ pros :

  1. Speed
  2. Reusability of existing C++ code
  3. All OpenCV API available

OpenCV Java pros :

  1. Easier to deploy
  2. Easier to implement
  3. Easier to debug

Comments

0

Please take a look on it for open cv android version

https://docs.opencv.org/2.4/doc/tutorials/introduction/android_binary_package/O4A_SDK.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.