• No results found

OpenCV on Android Platforms

N/A
N/A
Protected

Academic year: 2021

Share "OpenCV on Android Platforms"

Copied!
31
0
0

Loading.... (view fulltext now)

Full text

(1)

OpenCV on Android Platforms

Marco Moltisanti

Image Processing Lab – http://iplab.dmi.unict.it

[email protected]

(2)

Outline

• Intro

• System setup

• Write and build an Android app

(3)

A couple of words about Android / 1

• Android is a Linux-based OS, oriented to mobile devices;

• Android, Inc. was founded in 2003 by Andy

Rubin, Rich Miner, Nick Sears and Chris White; • Google acquired Android, Inc. in 2005;

• In 2007, Open Handset Alliance, a consortium including Google, HW manufacturers and TC

operators, unveiled Android as its first product, a mobile device platform.

(4)

A couple of words about Android / 2

(5)

A couple of words about Android / 3

• Applications for Android OS can be acquired through an app store, such as Google Play or the Amazon App Store;

(6)

Android Apps / 1

• An Android app is packaged and distributed as an Android Package, i.e. a file with apk

extension. All the code and data in a single apk file is considered a to be one application. • Each app lives in a sandbox inside the

Linux-based Android OS.

(7)

MyApp

Android Apps / 2

A single screen with a user interface Run in

background Manage data

(8)

Android Apps: file Manifest

• The system must know the existence of the application’s components.

• A «manifest» file, named

AndroidManifest.xml, is needed in order to:

– Declare components;

– Identify user permissions (e.g. Internet Access); – Declare minimum API level;

(9)

Android Apps

• An exhaustive view of Application’s

architecture would take too much time… • Further informations available at

(10)

Let’s start!

• First of all, we need to setup our work environment.

(11)

Ingredients

Java SDK 6 or

higher Eclipse IDE

(12)

Recipe / 1

• Download and install Java SDK from

http://www.oracle.com/technetwork/java/jav

ase/downloads/jdk7u9-downloads-1859576.html

• Let JAVA_FOLDER be the folder where we

(13)

Recipe / 2

• Download and install Android SDK from

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

• Download and unzip Android NDK from

(14)

Recipe / 3

• Download and unzip Eclipse IDE for Java Developers from

http://www.eclipse.org/downloads/

• Install the Android Development Tools (ADT) plugin for Eclipse:

http://developer.android.com/sdk/installing/insta lling-adt.html

(15)

Recipe / 4

• A good quick start guide is available at

(16)

Android application structure

Jni C/C++ application source code Control the C++ build process

Android.mk and Application.mk Written with Makefile syntax Libs Compiled libs

Res Resources of the application Images

xml files describing UI layout

Src Java code of the application

AndroidManifest.xml essential information about

application to the Android system:

Name of the Application

Name of main application’s package Components of the application Required permissions

Project root folder

(17)

Hello World! / 1

• Click on the highlighted button (if you don’t

have it, you have to

(18)

Hello World! / 2

• Fill the form and click next.

(19)
(20)

Run, Hello World, run! / 1

• To run our HelloWorld! App we have to setup a Virtual Device.

• This can be done using Android Virtual Device Manager, that comes with the SDK.

(21)

Run, Hello World, run! / 2

• From Eclipse, click Run (CTRL+F11) and select the Android App

modality

(22)

A bit deeper… / 1

• The user interface (UI) of an application is stored in a xml file, which contains each component’s settings.

• The UI can be created modifying the xml or using the tools provided by Eclipse.

(23)

A bit deeper… / 2

• The logic part is in a java file, with the same name of the activity we’re working on.

• In our example, it’s in MainActivity.java

• It is possible to access layout elements using the

findViewById method.

• public View findViewById (int id)

(24)

Events Handling

• Nobody likes a static UI!

• Here we use the Java event handling paradigm: Event Listeners!

• Each event has its own listener – onClickListener

– onCheckedChangeListener – …

(25)

OpenCV for Android

There are 3 ways to use OpenCV on Android

1. Basic level

• OpenCV Java API only + Android SDK.

2. Advanced level

• OpenCV native interface + Android NDK.

3. Hacker level

• We don't suggest this way.

• 1 & 2 use prebuilt OpenCV package:

(26)

Basic level

• OpenCV exposes almost all its functionality to Java including camera

• You don't even need to dive into NDK stuff

• You simply add a reference to the OpenCV, import its classes and move forward

• The overhead is equal to a cost of one or several JNI calls

(27)

Advanced level

• The Android way is writing all your code in Java

• Sometimes it is not enough and you need to go to a

native level and write part of your application in C/C++:

– For example: you already have some computer

functionality which is written in C++ but do not want to rewrite the C++ code to Java.

• Add a class with native methods and wrapping your C++ functionality into the Java part of your Android application

(28)

Hacker level

• We don't recommend this way, but it is useful if you want to work with OpenCV sources.

– Implement some new features – Optimize the performance

– Submit a bugfix

(29)

Install OpenCV Manager on the VD / 1

(30)

Install OpenCV Manager on the VD / 2

• Let ANDROID_SDK be the folder where we installed the SDK;

• Let ANDROID_OPENCV be the folder where we put the opencv4android libs;

• Open a shell:

– cd ANDROID_SDK\platform_tools – adb install

(31)

And now?

String code = "Let’s go to write down the code!";

References

Related documents

Furthermore, many signs indicate that the pharmaceutical industry – and in particu- lar the clinical research sector – will be relying on the help and support of freelancers more

The primary aim of the present study is to examine whether there is any significant relationship between patterns of cash flow components and financially

 Under ADB Education IV Project, rehabilitation and expansion of the 31 out of the targeted 42 traditional secondary school is ongoing with additional 15 seed secondary

As with the power delivery system, the K2 cost is based on the maximum (rated) power capacity of the data center, i.e. if a data center is built to operate at 10 MW, then

Seventeen of the items evaluated the academic staff satisfaction with the working conditions in four aspects including: management and ensuring health and safety

As seen from the Table 3, at 1% level of significance, moisture level, feed rate and pneumatic pressure had considerable impact on fully fractured and fragmented, and

and LCP olecranon plate Good Fair Fair Fair Excellent Excellent Excellent Good Good Poor Good LOM Ulnar nerve Sx Heterotophic ossification LOM, ulnar nerve Sx Ulnar nerve Sx

The Cisco MDS 9506 multilayer director provides an open platform that delivers the intelligence and advanced features required to make multilayer intelligent SANs a reality,