/opencv-android-forked

Android Library Project for OpenCV - currently ver. 3.4.1

Primary LanguageJavaMIT LicenseMIT

Forking Note:

Due to how Githiub computes LFS bandwidth, the current version of this repository is located here.


opencv-android

OpenCV4Android, packaged as a .aar for direct use without depending on the stupid OpenCV Manager app.

Building an .aar of OpenCV-3.x.y

Building OpenCV-3.x.y for Android is actually quite simple, its just not obvious where to get the pieces and the OpenCV docs hard-sell the "OpenCV Manager" in favour of the better and easier direct integration approach.

Here's the steps I used to create my .aar:

  1. Download and extract the OpenCV4Android bundle
  2. Create a Library Project in Android Studio
  3. Copy the java source files from OpenCV4Android into src/main/java
  4. Drop the OpenCV native libraries into src/main/jniLibs
  5. Run the gradle build
  6. Et voila, .aar file

install

Reference the maven repository

repositories {
  maven {
    url  "https://dl.bintray.com/thitu/releases"
  }
}

Include the .aar in your build.gradle file:

dependencies {
    compile "com.github.thitu:OpenCV-Android:3.2.0"
}

Bootstrap OpenCV in your Java code:

import org.opencv.android.OpenCVLoader;

...

if (OpenCVLoader.initDebug()) {
  // do some opencv stuff
}

Optional but recommended: to keep the downloaded APK size to a minimum, build separate APK's per architecture (approx 10MB each vs 42MB for universal) by placing the following inside the 'android' gradle directive of your application's build.gradle:

splits {
  abi {
    enable true
    reset()
    include 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
    universalApk false
  }
}

Disclaimer: This project is simply my bundling of OpenCV as an Android Library. I am not otherwise involved in the OpenCV project, and all credit for the wonderful OpenCV library goes to the developers thereof.