How to Use opencv in Android (Latest Version)

Source: Internet
Author: User

The latest Java version of Android

 

I. Android Development Environment

1. Download Sun JDK 7

Http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

Note the configuration of environment variables. You must use the new version and JDK 6. However, if you use an earlier version, you cannot create an android project in eclipse.

2. Download the android SDK and Elipse

Http://developer.android.com/sdk/index.html

This link downloads both the android SDK and eclipse. Although these versions of eclipse are different, they are equally useful.

I put it in this location D: \ adt-bundle-windows-x86-20130514

3. Download the android SDK component

Open the androidsdk and give a link to how to download components.

Http://developer.android.com/sdk/exploring.html

I am using the latest version 4.2.2.

4. Install and download ADT plugin online

 

Open eclipse, select "Help-> install new software", and click "add,

In the Add repository dialog box, enter "ADT plugin" in the name column ",

Enter the https://dl-ssl.google.com/android/eclipse/ in the location column,

Click OK. In the available software dialog box, select all the single slaves and click Next until finish. After the ADT is installed, restart eclipse.

 

Another method is to download the ADT and install it. Because the ADT version is subject to SDK restrictions, we do not recommend that you use this method.

5. Android ndk

Visit the http://developer.android.com/sdk/ndk/index.html to download the latest Android ndk, is a zip package, just extract to a certain path,

For example, "d: \ android-ndk-r8e", and then add this path to the system's environment variable path.

Note: Do not use version 7. If this version has bugs, use version 8.

6. cygwin

Visit http://cygwin.com/index.htmlto download the latest cygwin. it is best to install a full cygwinkit. Assume that "C: \ cygwin \ bin" is installed under "C: \ cygwin \ bin" and added to the path of the system environment variable. In order to conveniently call Android ndk under the command line, find the directory "C: \ cygwin \ home \ (your username)" and open the file ". bash_profile ", add the following two lines at the bottom of the file:

Ndk =/cygdrive/f/android-ndk-r6b-windows/android-ndk-r6b

Export ndk

In this way, you can call ndk in the form of "$ ndk/ndk-build" in the command line.

Easy mistakes:

1. cygwin download is an extremely troublesome task. We recommend that you download all the entire dedevils. Never download them.

2. The ". bash_profile" file is UNIX, not windows. After modification, you must use the software to change to the unix version.

7.download the latest opencv-2.4.5-android-sdk.zip File

 

Ii. configuration method

1. Create a project and a workspace

Create a workspace D: \ work \ opencv4android \ testopencv and use eclipse to open

Name the helloimage project "haveimgfun", change the activity name to haveimgfun, enter com. testopencv. haveimgfun in the package name, and click Finish. Activity name is helloimagelayout name is main 2. Import the opencv library in the project and decompress opencv SDK 2.4.5 under D: \ work \ opencv4android \ testopencv to import it to the Workspace: file-> Import select the import path as follows, select all

 

Click Finish. This result is returned (no errors)

 

In package explorer, right-click your project and select Properties from the pop-up menu. In the pop-up Properties window, right-click android on the left, click Add in the lower-right corner, and select opencv-

3. write code 1. Change the content of Main. xml under Res-> layout to the following:
<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "vertical" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <button Android: layout_height = "wrap_content" Android: layout_width = "fill_parent" Android: Id = "@ + ID/btnndk" Android: TEXT = "use C ++ opencv for processing"/> <button Android: layout_height = "wrap_content" Android: layout_width = "fill_parent" Android: id = "@ + ID/btnrestore" Android: text = ""/> <imageview Android: Id = "@ + ID/imageview01" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"/> </linearlayout>

The current file path is D: \ work \ opencv4android \ testopencv.

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.