Skip to main content

Overview

OpenCV provides Java bindings through an automatic code generation system. The bindings include both the Java API (JAR file) and native JNI libraries, enabling OpenCV functionality in standard Java applications and Android apps.

Installation

Desktop Java Applications

Add OpenCV to your pom.xml:

Android Applications

Building from Source

For custom builds:

Quick Start

Loading the Native Library

Before using OpenCV in Java, load the native library:
On Android, use OpenCVLoader to load the library asynchronously or through the OpenCV Manager.

Android Initialization

Core Concepts

Mat Class

The Mat class represents images and matrices:
Memory Management: Unlike Python, Java OpenCV requires manual memory management. Always call mat.release() when done with Mat objects to prevent memory leaks.

Code Examples

Reading and Writing Images

Image Processing

Android Camera Processing

Face Detection

Working with Matrices

Android Best Practices

Using CameraBridgeViewBase

Always enable and disable the camera view in onResume() and onPause() to properly manage resources.

Common Patterns

Resource Management

Resources

Next Steps