Skip to content

Quick Start

LucQuebec edited this page Jul 5, 2026 · 1 revision

Quick Start (official OpenCV AAR)

The fastest path — no NDK, no source build.

1. Add the dependency

// build.gradle.kts (module)
dependencies {
    implementation("org.opencv:opencv:5.0.0.1")
}

mavenCentral() is already in a default Android project's repositories.

2. Initialise

Call this once before using OpenCV (e.g. in Application.onCreate):

import org.opencv.android.OpenCVLoader

if (!OpenCVLoader.initLocal()) {
    Log.e("OpenCV", "OpenCV initialisation failed")
}

The AAR bundles the native .so — nothing to copy manually.

3. Use it

import org.opencv.android.Utils
import org.opencv.core.Mat
import org.opencv.imgproc.Imgproc

val src = Mat()
Utils.bitmapToMat(bitmap, src)
Imgproc.cvtColor(src, src, Imgproc.COLOR_RGBA2GRAY)
Imgproc.Canny(src, src, 80.0, 160.0)

See examples/ for full snippets (edge detection, DNN face detection).

What's included

The official AAR covers core: core, imgproc, imgcodecs, video, calib, features, dnn, objdetect, photo, stitching.

Not included: the opencv_contrib modules (face recognition, tracking, ArUco, text, ml, Haar/HOG, gapi, …). See Official vs Contrib. For those without rebuilding, see Pro Integration.

Clone this wiki locally