(personally I use Android but no I do not have a “favorite”) • Computer Engineering, University of MD, College Park • Marylander living in Colorado • Gamer (video, board, card, anything): currently Dota 2, Don’t Starve, Kingdom Rush, 7 Wonders 3
do What features the API supports Typical for Android development: Build.VERSION etc. What features the device camera has Typical for Android development: use-feature and PackageManager Specific to camera: querying support level from the Camera class What you can do
vital to separate critical features from optional ones. • Highly recommended to use specific <uses-feature> to specify required features. Why? • <uses-permission android:name="android.permission.CAMERA" />! - “This will automatically enforce the <uses- feature> manifest element for all camera features.” 5
permission (without any <uses-feature> specifications) means that a device would require the following: - a back-facing camera - a front-facing camera - auto-focus - flash • If you do not need any of the above, specify <uses- feature> with android:required=false 6
setup + access point Preview callback Shutter callback Picture taking callback ! ! ! Auto Focus callback Zoom listener Face detection listener Camera.CameraInfo front or back, orientation, shutter disable Camera.Parameters preview, picture output, “photography stuff”: features/settings dependent on the device camera: flash modes, color effects, scene modes, white balance, etc. Camera.Area “photography stuff”: focus and metering, rectangular bounds + weight Camera.Face “face stuff”, bounds and feature (left eye, right eye, mouth) coordinates for a face identified with face detection, confidence score APK 14+: Data objects Device camera information + settings Camera.Size width and height: picture size, video size, preview size
your layout for the camera preview. Implement a SurfaceHolder.Callback to listen for #surfaceCreated, #surfaceChanged, and #surfaceDestroyed Pass the callback to the SurfaceHolder instance of the SurfaceView. Open a Camera instance: Camera#open Get the Camera.Parameters and perform any initial setup. After the preview surface has been created, call Camera#setPreviewDisplay with the SurfaceHolder. Start the preview: Camera#startPreview. wait for surface to be created
setting up the camera preview: - The surface is destroyed when the visibility of the SurfaceView is set to View.INVISIBLE. - Camera#release will stop the preview - Camera#stopPreview nulls out callbacks, stops face detection - Camera#setPreviewDisplay should be called after the surface is created. No error, just no preview. - Any changes to the preview size must be between calls to Camera#startPreview and Camera#stopPreview 9
set up, call takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)! • PictureCallback parameters = 3 picture formats: raw (uncompressed), postview, and JPEG. - Raw and postview availability depends on device - takePicture stops the camera preview so Camera#startPreview should be called in/after callbacks 10
particular device camera - orientation: angle of rotation when facing the camera for the camera image to match the natural orientation of the device - facing: camera direction - whether the shutter sound can be disabled • Camera.getCameraInfo: camera IDs are indices 0 to n-1 • Use CameraInfo to swap between front and back - Use PackageManager to check if a front camera exists unless you have front camera as a requirement for device - Close the current camera before swapping 11
Empirically, trying to work with camera/display rotation and configuration changes sucks: - Complicated. - Orientation changes do not coordinate well with camera orientation changes. - Can change the activity orientation change animation in API 18+). 13
fixed activity orientation. - Call Camera#setDisplayOrientation to adjust for CameraInfo.orientation. - Use the OrientationEventListener to rotate the UI. - Does mean that your application thumbnail may look sideways in the Recent Apps list. 14
stuff (settings and modes) is set in Camera.Parameters. - A couple of features (auto-focus and flash) have <uses-feature> and PackageManager values. - Most other features will provide support information via methods in Camera.Parameters - Example: getMinExposureCompensation returns 0 if exposure compensation is unsupported - Several getters provide lists of valid values for features or modes that have different value ranges on different devices. - Note that API level also factors: face detection and metering areas are API 14+. 15
Camera.Parameters can be changed while preview started and will take effect immediately. • For saving/restoring settings state, handy methods: Camera.Parameters#flatten and Camera.Parameters#unflatten • Important: - Always call Camera#getParameters, do not hold onto Camera.Parameters instances - To actually change parameters, set values on a Camera.Parameters instance and call Camera#setParameters 16
on Camera.Parameters: - Auto-focus may cause the flash to activate depending on the camera and its drivers. - Setting a scene mode overrides other parameters so if camera parameters have UI feedback may want to call Camera#getParameters and update. • Other common camera/photo features done through Camera.Parameters: - GPS coordinates and timestamps for geotagging photos. - Image size and quality - Note that image size and preview size are independent 17
and metering areas and focus areas • Camera.Area: defines bounds within the viewfinder for the camera to use in metering and focus • Camera viewfinder/sensor has its own coordinate system different from a View’s coordinate system. • Otherwise, just like setting other camera parameters 18
Camera.FaceDetectionListener, Camera#startFaceDetection, Camera#stopFaceDetection! • Camera.Face camera coordinates of bounds of face in viewfinder; maybe left eye, right eye, mouth position; also confidence • camera/sensor coordinates -> view coordinates 20
CONTACT HUYEN TUE DAO THINGS TO CHECK OUT Standford Digital Image Processing Class http://www.stanford.edu/class/ee368/Android/index.html ! Android Design in Action https://www.youtube.com/watch?v=OLSa7fErTAM