Add OpenCV library into Android Studio
OpenCV (Open Source Computer Vision Library) provides a lot of useful implementation for computer vision and image processing. It has C++, C, Python and Java interfaces and supports Windows, Linux, Mac OS, iOS and Android. In this article, I am going to show you how to add OpenCV into Android Studio step by step.
First, go to OpenCV release page, download and unzip the Android pack version (220.127.116.11 for example).
Next, lunch Android Studio and open(or create ) a project. In Android Studio, select “File > New > Import Module…”
Find your “opencv-18.104.22.168-android-sdk” folder and navigate to “OpenCV-android-sdk\sdk\java”
Select sub directory “OpenCV-android-sdk\sdk\java”
Then, you will see “openCVLibrary24132” in your project
Open build.gradle for openCVLibrary 24132, modified “compileSdkVersion”, “buildToolsVersion”, “minSdkVersion” and “targetSdkVersion” to be the same as app build.gradle
Open “Project Structure” in File > Project Structure in Android Studio and add module dependency as shown below
In Android Studio, change tab to “Project” and create a new directory named “jniLibs” under directory “Your Application Root\app\src\main\”
Copy all files from “opencv-22.214.171.124-android-sdk\OpenCV-android-sdk\sdk\native\libs” into “jniLibs” directory
At last, we need to load OpenCV library in our App. Add the following code in your main activity and your are ready to use any function in OpenCV!