Configure OpenCV 3.1 in Android Studio

Source: Internet
Author: User

Configure OpenCV 3.1 in Android Studio

Go to the official website (http://opencv.org/) download OpenCV for android and unzip, do not know why, tried a few download is very slow, often disconnected, and then suddenly downloaded very smoothly. Directory structure:

Configure OpenCV for the project

1. Create an Android project. Open Android Studio and click File> New Project... ;


2. Import the OpenCV library. Click File-> New-> ImpZ plugin? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcnQgTW9kdWxloa08YnI + c1_vcd4kpha + pgltzybzcm9" http://img0.tuicool.com/BjYJJrU.png! Web "alt =" \ ">

In the displayed window, find the SDK \ java folder under OpenCV Android sdk, for example, C: \ dev-lib \ OpenCV-android-sdk \ java:


Click Next. Keep the default options unchanged, and click Finish to import the OpenCV Library:


In this case, Android Studio automatically updates the project configuration. Because of the default configuration of the OpenCV library, many errors will occur in this process (as shown in the bottom red box ). In this case, we need to modify the OpenCVLibrary310 \ build. gradle file, and then re-Synchronize the Gradle Configuration:

Modify the OpenCVLibrary310 \ build. gradle file as follows:

apply plugin: 'com.android.library'android {    compileSdkVersion 23    buildToolsVersion "23.0.2"    defaultConfig {        minSdkVersion 16        targetSdkVersion 23    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'        }    }}
applyplugin: 'com.android.library'android {compileSdkVersion 23buildToolsVersion "23.0.2"defaultConfig {minSdkVersion 16targetSdkVersion 23}buildTypes {release {minifyEnabledfalseproguardFilesgetDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'}}}

After modification, click Try Again as shown in the preceding figure, or click the button above Android Studio to synchronize the Gradle configuration of the project. After synchronization, You can integrate the OpenCV module into the Android project.

3. Integrate the Android project with OpenCV. Click File-> Project Structure... :

In the displayed Project Structure window, select the app on the left and Dependencies on the right. Then, click the button and select Module dependency:

In the displayed window, select OpenCVLibrary310, click OK twice, and save and close the two windows:

Now, your Android project supports OpenCV development!

In addition, do not forget to install the OpenCV Manager of the corresponding architecture before debugging the APP on the device. This package contains all the library functions of OpenCV. Otherwise, the following error occurs:

OpenCV Manager is located in the apk directory of OpenCV Android SDK, such as C: \ dev-lib \ OpenCV-android-sdk \ apk, and then selects the installation package based on your device. For example, if the CPU of a mobile phone is ARM clock.

For the actual device, copy the apk of OpenCV Manager to the device for installation. For a virtual device, run the adb install command in the command prompt. For example:

C:\dev-lib\android-sdk\platform-tools\adb install C:\dev-lib\OpenCV-android-sdk\apk\OpenCV_3.1.0_Manager_3.10_x86.apk
C:\dev-lib\android-sdk\platform-tools\adbinstall C:\dev-lib\OpenCV-android-sdk\apk\OpenCV_3.1.0_Manager_3.10_x86.apk


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.