This is a showcase how to get OpenCV up and running with just the Android NDK
- This uses the NDK Camera2 API to get the image buffers
- It then uses OpenCV to processes the image buffer
- Lastly it gets the NDK ANativeWindow and displays the image for live previewing
- Android API 24 (Nougat) or greater
- Android Studio 2.3+
- OpenCV-Android-SDK
- Clone or download repo and open the OpenCV-NDK folder. (The 2nd one that is the child)
- Click "Open project" in Android studio and find the folder saved in
- Change the OpenCV Android SDK library path in Android.mk file to your
my/path/to/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk
- Move all files in the Asset folder to your device
- This is annoying af, but no good solution I could find easily fixed it since OpenCV requires a file string which the NDK only gives you a file descriptor.
- Currently the folder location pointing to the asset files are listed in the CV_Main.h private values so make sure it matches
- On your computer go to the
./OpenCV-NDK/app/src/main/assets
folder and with your device plugged in runadb push haarcascade_frontalface_alt.xml /sdcard/Download/opencv/haarcascade_frontalface_alt.xml
adb push haarcascade_eye_tree_eyeglasses.xml /sdcard/Download/opencv/haarcascade_eye_tree_eyeglasses.xml
To make compiling faster I only have it load and run ARM 64-bit (arm64-v8a). To add a different abi architecture:
- In the build.gradle file add
, armeabi-v7a
so gradle - in the Application.mk file add
armeabi-v7a