Kuo-Chin Lien
Develop a Hello World project in Android Studio Capture, process, store, and display an image on Android phones Other sensors on Android phones
If you have been using Eclipse with ADT, be aware 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: 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 resolution Java 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
AVD manager - choose a device for emulation (Tools->Android->AVD Manager) Tip: What s theandroid version and API level of your phone? SDK manager download necessary packages (Tools->Android->SDK Manager)
.java Coding the behavior of your program.xml Settings (GUI/hardware arrangement) for the app.gradle Make file logcat In.java, use Log.d(TAG, debug_message); to print debug_message at logcat at run time
A snapshot of the IDE
.java: Coding the behavior of your program
.xml: GUI design Design mode and text mode
.gradle: Make file
Logcat: In.java, use Log.d(TAG, debug_message); to print debug_message at logcat at run time http://developer.android.com/tools/debugging/debugging-log.html
run Debug
In the debug mode, you can pause at the 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, click Resume Program.
2. Double click to edit the text More widgets 1. Go to the Design tab
1. Connect your Android phone to the computer 2. Turn on the phone, go to Developer Option, enable USB Debugging 3. Run your app as before
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 Display the grayscale image Save the grayscale image
Download: http://opencv.org/ Import OpenCV as a library www.ece.ucsb.edu/~kuochin/290i/setupas.html Aside: $50,000 award for 11 CV challenges
Hardware permission GUI Image capture, processing, and display
Load OpenCV BaseLoaderCallback Will be called after OpenCV is loaded Set up a listener e here. e When the button is clicked, c call captureimage. captureimage Show the preview mode to the user Save an image Convert image to gray using OpenCV
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) { } Start the camera intent startactivityforresult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); ACTIVITY REQUEST CODE); // will enter the preview mode Receive the intent result void onactivityresult (int requestcode, int resultcode, Intent data){ // process the captured frame here } http://developer.android.com/guide/topics/media/camera.html#intents
OpenCV provides various functions to process an image: blur, edge detection, resize, morphological operations etc. We can call CvtColor( ) to transform an image from RGB to other color spaces: Imgproc.cvtColor(InputBuffer, OutputBuffer, Imgproc.COLOR_RGB2GRAY); See more detail here: http://docs.opencv.org/modules/imgproc/doc/mis / d /i /d / i cellaneous_transformations.html#cvtcolor See more functions here: http://docs.opencv.org/modules/imgproc/doc/im gproc.html
Sample code downloadable here: http://cs.ucsb.edu/~efujimoto/mobile/other/main b h Activity.java
Sample code for recording a video http://developer.android.com/training/camera/videobasics.html p 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 ), you need to know the Camera class: http://developer.android.com/guide/topics/media/camera.html#customcamera http://developer.android.com/reference/android/hardware/camera.html 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 OpenCV4Android: http://docs.opencv.org/platforms/android/refman.html
To accomplish the homework, you need the permissions to ACCESS_FINE_LOCATION and/or others ACCESS_COARSE_LOCATION INTERNET... See a list of the permissions i you can request: http://developer.android.com/reference/android/manifest.pe rmission.html
Location: A data class representing a geographic 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: http://developer.android.com/reference/android/location/locatio n.html http://developer.android.com/reference/android/location/locatio nmanager.html
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 rhtml r.html http://developer.android.com/reference/android/hardware/senso rmanager.html http://developer.android.com/reference/android/hardware/senso revent.html
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/ edu/~kuochin/290i/tut orialmaterial.zip