There are two ways for a developer to use OpenCV4Android. First is to use the default distribution package, which is built for every public OpenCV release and is published on the Sourceforge. We highly recommend this way, because package is thoroughly tested and this is the only officially supported method of using the OpenCV4Android. For example, OpenCV Manager is supported if only you’re using standard SDK, it lets your application use hardware-specific optimizations, automatically receive stability updates and use single OpenCV copy on user device.
Another way for you is to build everything from sources, because OpenCV is free! But in this journey you can count on yourself only. Below is the more detailed discussion of available options for developers.
Use the OpenCV4Android distribution
Basic level – OpenCV’s Java API only. OpenCV exposes almost all its functionality to Java (including camera), so you don’t even need to dive into NDK stuff. You simply add a reference to the OpenCV, import its classes and move forward. All the computations are performed on the native level, hence the overhead is equal to a cost of one or several JNI calls. Several sample applications are written in pure Java, so you can play with them and understand if the proposed approach is suitable for your application.
- Fast ramp-up, the simplest way to develop for Android with OpenCV.
- Easy development in a language with garbage collection.
- Complex CV logic (with many calls to OpenCV) will work slowly because of additional cost of JNI calls.
- Not 100% availability of OpenCV C++ API.
Tutorial for you: “OpenCV for Android SDK”.
Advanced level – OpenCV’s native interface. It is usually used for professional development, and we consider it as a “true” way for development with OpenCv4Android. As you know, Android allows you to call native functions, that means that you can use the original C++ OpenCV interface. Approach, which is described above, works in many cases, but if the processing pipeline is long, JNI calls may consume too much time. In such a case you can encapsulate all the functionality in a single C++ class and call it just once per frame. What is also important is that you can develop (and debug!) all the CV logic on your host machine. C++ code in OpenCV is cross-platform, that means that you can port your desktop code to mobile devices.
- Maximum of the performance.
- 100% availability of OpenCV C++ API.
- Development of the core CV functionality on a host platform.
- You can run your code on other platforms: iOS, Windows Phone…
- You can mix Java and native code.
- You should study Android NDK.
- Development becomes a bit more complicated. But only in the beginning.
Tutorial for you: “Native/C++”.
Build OpenCV4Android from sources
This is a hacker level. Actually it is not a special option we propose, but we are open-source (BSD license), so you can take the advantage of it! We don’t recommend this way, but if you want to work with the OpenCV sources, you’re welcome! You’re probably want to implement some new features, optimize the performance, submit a pull request. May be you simply want to have access to the latest OpenCV features and keep your finger on the pulse of development.
- Access to the latest features
- The full freedom of OpenCV hacking
- You should know the full stack of OpenCV dev tools
- You’ll be an OpenCV beta-tester 😉
“Tutorial” for you: “Building OpenCV4Android from trunk”.