1. Download
Go to the official website (http://opencv.org/) to download opencv4android and unzip. The directory structure is as shown.
Among them, the SDK directory is the class library we need to develop OPENCV, the Samples directory contains a number of OPENCV application examples (including face detection, etc.), for our Android under the OpenCV development to provide reference The doc directory is the usage instructions and API documentation for the OpenCV class library, while the APK directory holds the opencv_2.4.3.2_manager_2.4 application installation package corresponding to each kernel version. This app is used to manage the OpenCV class library in your mobile device, and before you run the OpenCV app, you must make sure that the opencv_2.4.3.2_manager_2.4_*.apk is installed on your phone. Otherwise the OpenCV app will not run because the OpenCV class library cannot be loaded (the next article will show you how to run OpenCV without installing OpenCV Manager in advance).
2. Introducing OpenCV to Android Studio
In Android Studio, select the File->import Module, locate the OpenCV decompression path, and select the Sdk/java folder.
3. Update build.gradle Information
In the upper left corner of Android studio, select Project View, in the oepnCVLibrary2411 folder, Open Build.gradle (There are many names of files, be sure to find the OpenCV library file), modify the file 1) compilesdkversion 2) buildtoolsversion 3) minsdkversion 4) targetsdkversion the content to match the information in the Build.gradle in the app folder. Click Try again in the yellow hint box above to update.
4. Add Module Dependency
Right-click the app folder, select Open Module Settings, in the app Module's dependencies column, tap the green plus sign in the upper-right corner, add openCVLibrary2411, click OK.
5. Copy the Libs folder into the project
In OpenCV's unpacking package, copy the Sdk-->native-->libs folder, paste it under the App-->src-->main directory under Project view, and rename it to Jnilibs.
Since then, the OPENCV environment has been well-configured. You can put the layout file in Opencv-android-sdk-->samples-->tutorial-1-camerapreview, Java file, into the project, Modify the Androidmanifest.xml, add permission to use the camera, and test for success.
How to configure Android studio using OpenCV