Book Image

Android Application Programming with OpenCV 3

By : Joseph Howse
Book Image

Android Application Programming with OpenCV 3

By: Joseph Howse

Overview of this book

<p>Android Application Programming with OpenCV 3 is a practical, hands-on guide to computer vision and mobile app development. It shows how to capture, manipulate, and analyze images while building an application that combines photography and augmented reality. To help the reader become a well-rounded developer, the book covers OpenCV (a computer vision library), Android SDK (a mobile app framework), OpenGL ES (a 3D graphics framework), and even JNI (a Java/C++ interoperability layer).</p> <p>Now in its second edition, the book offers thoroughly reviewed code, instructions, and explanations. It is fully updated to support OpenCV 3 and Android 5, as well as earlier versions. Although it focuses on OpenCV's Java bindings, this edition adds an extensive chapter on JNI and C++, so that the reader is well primed to use OpenCV in other environments.</p>
Table of Contents (13 chapters)
Android Application Programming with OpenCV 3
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding the role of JNI


JNI enables Java code to call C or C++ code (and vice versa). OpenCV4Android, Android SDK, and the Java standard libraries all rely on JNI. That is to say, these major Java libraries are partly built atop C++ or C libraries.

OpenCV is largely written in C++. Although the library provides a Java interface (OpenCV4Android) and a Python interface as well, most parts of these interfaces are thin layers atop the C++ implementation. For example, an org.opencv.core.Mat object (in the Java interface) or a NumPy array (in the Python interface) is backed by a cv::Mat object (in the C++ implementation), and they share a reference to the same data; there is no duplication of data.

When OpenCV's Java or Python interface forwards a function call to the C++ implementation, it does incur a small overhead cost. If our code makes thousands of OpenCV function calls per frame (for example, one or more calls per pixel per frame), we might begin to worry about this overhead. Typically...