Install OpenCV mac environment/Linux environment in Android Studio

Source: Internet
Author: User

Install OpenCV mac environment/Linux environment in Android Studio
Install OpenCV in Android Studio

For female programmers, every time they install software or configure an environment, they often crash. This is also true for Aunt ape ~ (Ah, do I say I'm an aunt ?)

Okay, let's get down to the truth ~ Let's write down how to install it. However, if you try to install the tool, you will find new bugs ~ The learning process is painful. If you have successfully installed it, It's kensen ~ (It's like seeing the sun in Beijing today ~ This sister is in the lab study program Orz)

Installation environment

Installation environment: MacBook Pro OS X EI Capitan 10.11.3
Development Environment: Android Studio 2.1, Official Website: link AndroidStudio
OpenCV: VERSION 3.1, link OpenCV
After the download, the files and clips are included:

Installation Method 1) Open Android Studio and create a project

File-> New Project-> Next-> Finish.

2) Import OpenCV

File-> New-> Import Module-> [sdk in the opencv folder-> java]-> Next-> Finish.

3) Update build. gradle

Switch to build. gradle under Project> OpeCVLibrary310.

4) add module dependency

Switch to Project> app> Open Module Setting

-> Dependencies-> "+"-> module dependency

-> OK

This is what I intercepted, because I have installed it, and I cannot display this ~ My procrastination does not know 2333

5) join libs

Switch to android> app> new> JNI folder

-> Change Folder Location-> View the modification path-> finish.

-> [Sdk-> native-> All copies in libs in the opencv folder]

-> Copying jni in the app (Note: you do not need to copy all of them, but what do you need to copy)

6) Write a verification program

public class MainActivity extends AppCompatActivity {    private static final String TAG = "MainActivity";    static {        if (!OpenCVLoader.initDebug()) {            Log.d(TAG, "OpenCV not loaded");        } else {            Log.d(TAG, "OpenCV loaded!");        }    }    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);    }}

Thank you ~

7) set attributes

Switch to android-> Gradle Scripts-> gradle. properties-> write a command line-> Save

android.useDeprecatedNdk = true

I know you are lazy ~

8) THE END

Run in MainActivity. java ~

9) success. Give me some encouragement ~

Note: If you are a newly installed android studio, you may need to install NSK.
If you fail to run the task, an error is returned ~ Prompt that you need to install nsk ~
Method: Switch to Project> app> Open Module Setting> SDK Location to find the answer ~ Under normal circumstances, click to automatically install ~

Aunt is so old that markdown is so tired ....

Please do not change it if you have something to do with me ~ If you have any questions, I will definitely reply ~

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.