OpenCV for Android
Configure the OpenCV Android environment
- Download the SDK
The SDK directory structure is as follows:
OpenCV-android-sdk |_samples |_sdk | |_etc | |_java | |_libcxx_helper | |_native | |_3rdparty | |_jni | |_libs | |_arm64_v8a | |_armeabi_v7a | |_x86 | |_x86_64 | |_staticlibs | |_arm64_v8a | |_armeabi_v7a | |_x86 | |_x86_64 |_LICENSE |_README.androidCopy the code
-
Import OpenCV for Android SDK
- Create a new project in Android Studio
File → New → import Module
- Select the SDK folder under the previously downloaded package and click OK
- The Gradle configuration of the opencV SDK is compatible with the Gradle configuration of our new app. That is, the compiled version of the Gradle SDK in the SDK, the minimum version, and the target version are consistent with the app
app Gradle:
SDK Gradle:
- Add Opencv for Android dependency
File → Project Structure → Dependencies → app → + → Module Dependency → SDK
The OpeCV environment has been successfully migrated
- Initialize the OpenCV
But that’s not all. Now you can actually use the OpenCV library functions directly. OpenCV libraries need to be initialized before they can be used. This can be done with the following code:
private void OpenCVInit(a) { boolean success = OpenCVLoader.initDebug(); if (success) { Log.d(TAG, "OpenCV Lode success"); } else { Log.d(TAG, "OpenCV Lode failed "); }}Copy the code
Just call OpenCVInit() in onCreate()