• No results found

Develop a Hello World project in Android Studio Capture, process, store, and display an image. Other sensors on Android phones

N/A
N/A
Protected

Academic year: 2021

Share "Develop a Hello World project in Android Studio Capture, process, store, and display an image. Other sensors on Android phones"

Copied!
41
0
0

Loading.... (view fulltext now)

Full text

(1)

Kuo-Chin Lien

Kuo Chin Lien

(2)

`

Develop a Hello World project in Android

Studio

`

Capture, process, store, and display an image

on Android phones

on Android phones

(3)
(4)

` “If you have been using Eclipse with ADT, be aware

that Android Studio is now the official IDE for that Android Studio is now the official IDE for

Android, so you should migrate to Android Studio to receive all the latest IDE updates.”

` Where: ` Where:

http://developer.android.com/sdk/index.html ` System requirement (Windows):

Microsoft® Windows® 8/7/Vista/2003 (32 or 64-bit)2 GB RAM minimum, 4 GB RAM recommended

400 MB hard disk space + at least 1 GB for Android SDK, emulator system images, and caches

1280 x 800 minimum screen resolutionJava Development Kit (JDK) 7

Optional for accelerated emulator: Intel® processor with support for Intel® VT-x, Intel® EM64T (Intel® 64), and Execute Disable (XD) Bit functionality

(5)
(6)
(7)

`

AVD manager - choose a device for

emulation

Tip: What’s the Android (Tools->Android->AVD Manager) ◦ Tip: What s the Android

version and API level of your phone?

`

SDK manager – download necessary

packages

packages

(8)

`

.java

C d h b h f

Coding the behavior of your program

`

.xml

Settings (GUI/hardware arrangement) for the appSettings (GUI/hardware arrangement) for the app `

.gradle

Make file `

logcat

In .java, use

Log.d(TAG, debug message); Log.d(TAG, debug_message);

(9)
(10)
(11)

.xml: GUI design

(12)
(13)

Logcat:

In .java, use

Log.d(TAG, debug_message); 

to print debug_message at logcat at run time

(14)
(15)

` In the debug mode, you can pause at the

b k i i

breakpoints in your program

` To advance to the first line inside a method call,

click Step Into .

` To advance to the next line outside the current

method, click Step Out .

` To continue running the app normally ` To continue running the app normally,

(16)
(17)
(18)
(19)
(20)

2. Double click to edit the text

More More widgets

(21)
(22)

1.

Connect your Android phone to the

computer

2.

Turn on the phone, go to Developer Option,

enable USB D b

i

enable USB Debugging

(23)
(24)

`

A button to bring the user to the preview

mode which allows the user to take a picture.

`

The program automatically converts the

picture to grayscale

picture to grayscale

`

Display the grayscale image

`

Save the grayscale image

(25)

`

Download:

http://opencv.org/

`

Import OpenCV as a library

www.ece.ucsb.edu/~kuochin/290I/SetupAS.html

(26)

`

Hardware permission

`

GUI

(27)
(28)
(29)
(30)

`

Load OpenCV

d C llb k

`

BaseLoaderCallback

Will be called after OpenCV is loaded

Set up a listener here. When the button is clicked, Set up a ste e e e e t e butto s c c ed,

call captureImage.

`

captureImage

Show the preview mode to the userShow the preview mode to the userSave an image

(31)

` Compose a camera intent

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name private static File getOutputMediaFile(int type) {

private static File getOutputMediaFile(int type) { … }

` Start the camera intent

startActivityForResult(intent CAPTURE IMAGE ACTIVITY REQUEST CODE); // will startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); // will enter the preview mode

` Receive the intent result

void onActivityResult (int requestCode, int resultCode, Intent data){ void onActivityResult (int requestCode, int resultCode, Intent data){ // process the captured frame here

}

(32)

` OpenCV provides various functions to process an

image: blur edge detection resize morphological image: blur, edge detection, resize, morphological operations…etc.

` We can call CvtColor( ) to transform an image from

RGB t th l

RGB to other color spaces:

Imgproc.cvtColor(InputBuffer, OutputBuffer, Imgproc.COLOR_RGB2GRAY); ` See more detail here:

htt //d / d l /i /d / i

http://docs.opencv.org/modules/imgproc/doc/mis cellaneous_transformations.html#cvtcolor

` See more functions here:

http://docs.opencv.org/modules/imgproc/doc/im gproc.html

(33)

` Sample code downloadable here:

h b d f b l h

http://cs.ucsb.edu/~efujimoto/mobile/Other/Main Activity.java

(34)
(35)

` Sample code for recording a video

http://developer.android.com/training/camera/videobasics.htmlp p g

` Intent uses existing camera apps to help you capture images and

videos, which is convenient but less flexible. To provide more

compelling user experience (time lapse video, video snapshot …),

d k h l

p g p p p

you need to know the Camera class:

http://developer.android.com/guide/topics/media/camera.html#custom-camera

http://developer.android.com/reference/android/hardware/Camera.html

F API > 21 C 2

` For API >= 21, you can use Camera2

http://developer.android.com/reference/android/hardware/camera2/pack

age-summary.html

https://developer.android.com/samples/Camera2Basic/index.html

` OpenCV

OpenCV tutorial: http://docs.opencv.org/doc/tutorials/tutorials.html

(36)
(37)

` To accomplish the homework, you need the permissions to ACCESS_FINE_LOCATION and/or others … ACCESS_COARSE_LOCATION INTERNET . .. . S li f h i i

` See a list of the permissions you can request:

http://developer.android.com/reference/android/Manifest.pe rmission.html

(38)

` Location: A data class representing a geographic location.

` LocationManager: A class provides access to the system location ` LocationManager: A class provides access to the system location

services

private LocationManager locationManager;

locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria();

provider = locationManager.getBestProvider(criteria, false);

Location location = locationManager.getLastKnownLocation(provider); .

. .

` See the following links for details and more sample codes: ` See the following links for details and more sample codes:

http://developer.android.com/reference/android/location/Locatio

n.html

http://developer.android.com/reference/android/location/Locatio

(39)

private SensorManager sensorManager; private Sensor gyro;

sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); gyro = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);

sensorManager.registerListener(this, gyro, SensorManager.SENSOR_DELAY_NORMAL);

. . .

public void onSensorChanged(SensorEvent event) { // read the sensor output and do something … .

. }

` See the following links for more sensors with sample codes

http://developer.android.com/reference/android/hardware/Senso r html r.html ◦ http://developer.android.com/reference/android/hardware/Senso rManager.html ◦ http://developer.android.com/reference/android/hardware/Senso rEvent.html rEvent.html

(40)
(41)

`

Find this presentation at

http://www.ece.ucsb.edu/~kuochin/290I/29

0I_Android_Tutorial.pdf

`

Find sample codes at

http://www ece ucsb edu/~kuochin/290I/Tut

http://www.ece.ucsb.edu/ kuochin/290I/Tut

orialMaterial.zip

References

Related documents

wanpela kain liklik gras nogut, pikinini i holim kwik skin bilong man, i gat grinpela lip na mosong, em i olsem TOp, na 01 i save paitim manki long em long taim i sutim nus.

Therefore, in this study, we examine the relationship between brand equity (brand awareness, brand association, perceived quality, and brand loyalty) and brand purchasing intention

• Easily rotate the window 180° for safe cleaning of the outer glass from the inside.. • Adjust the bottom handle position to ventilate your home without opening

Chicken breast pieces and sliced red peppers covered in a creamy tomato and paprika sauce, topped with chorizo

This brief was written by the National Center to Improve Recruitment and Retention of Qualified Personnel for Children with Disabilities, known as the Personnel Improvement

In this paper, to deal with the periodic variations of parameters, a bi-objective mathematical model is proposed for the single allocation multi-period maximal hub covering

By considering these institutional responses, together with another response to the Cultural Policy Discussion Paper , the Digital Culture Public Sphere Discussion Paper