How to configure Android studio using OpenCV

Source: Internet
Author: User

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

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.