Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android L Camera2 API @ Women Techmakers Istanb...

Android L Camera2 API @ Women Techmakers Istanbul 2015

Android Lollipop brings completely new level of interaction with Camera - lets talk about Camera2 API.

Kseniia Shumelchyk

March 15, 2015
Tweet

More Decks by Kseniia Shumelchyk

Other Decks in Programming

Transcript

  1. #iwd, #wtm15 Agenda - Limitations of Android Camera API (Pre-L);

    - New Android 5 Camera API Features; - Camera2 Architecture; - Usage of Camera2 API.
  2. #iwd, #wtm15 Pre-L camera API - Designed for ‘Point and

    shoot’ - Limited access to streaming image data - Limited information about camera state - No manual camera control - 3 Primary operating modes (preview, capture, video) - Hard to implement features (burst mode, custom shutter lag) - No access to RAW data - Primitive custom settings
  3. #iwd, #wtm15 Features - Professional quality photo (DSLR vs ‘Point

    and Shoot’) - Fine grained control of lens, sensor, flash - RAW sensor output with capture metadata - On-device processing of camera data - HDR, Focus stacking - Individual frame control
  4. #iwd, #wtm15 Camera2 APIs android.hardware.camera2 This package models a camera

    device as a pipeline, which takes in input requests for capturing a single frame, captures the single image per the request, and then outputs one capture result metadata packet, plus a set of output image buffers for the request. The requests are processed in-order, and multiple requests can be in flight at once. CameraManager, CameraDevice, CaptureSession, CaptureRequest, CaptureResult
  5. #iwd, #wtm15 Opening the camera CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);

    manager.openCamera("0", new StateListener(){ @Override public void onOpened(CameraDevice device){ mCameraDevice = device; ... } ... }, null);
  6. #iwd, #wtm15 Creating surfaces CameraCharacteristics chars = (mCameraManager).getCameraCharacteristics("0"); StreamConfigurationMap configs

    = chars.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); Size [] sizes = configs.getOutputSizes(ImageFormat.JPEG); ImageReader mImageReader = ImageReader.newInstance(sizes[0].getWidth(), sizes[0].getHeight(), ImageFormat.JPEG, 2); Surface jpegCapture = mImageReader.getSurface();
  7. #iwd, #wtm15 Creating a CaptureSession List<Surface> surfaces = new ArrayList<Surface>();

    surfaces.add(previewSurface); surfaces.add(jpegCaptureSurface); mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(CameraCaptureSession session) { .. } }, null);
  8. #iwd, #wtm15 Contains the configuration for the capture hardware (sensor,

    lens, flash), the processing pipeline, the control algorithms, and the output buffers. Also contains the list of target Surfaces to send image data to for this capture. TEMPLATE_PREVIEW TEMPLATE_RECORD TEMPLATE_STILL_CAPTURE TEMPLATE_VIDEO_SNAPSHOT CaptureRequest
  9. #iwd, #wtm15 Building requests previewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); previewRequestBuilder.addTarget(previewSurface); captureRequestBuilder =

    mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); captureRequestBuilder.addTarget(jpegCaptureSurface); captureRequest = captureRequestBuilder.build(); previewRequest = previewRequestBuilder.build();
  10. #iwd, #wtm15 Setting up a Builder Builder builder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

    builder.addTarget(jpegCaptureSurface); builder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_INCANDESCENT); builder.set(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata.CONTROL_EFFECT_MODE_SEPIA); builder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_SINGLE);
  11. #iwd, #wtm15 CONTROL_AF_TRIGGER Whether the camera device will trigger autofocus

    for this request. CONTROL_AF_PRECAPTURE_TRIGGER Whether the camera device will trigger a precapture metering sequence when it processes this request. Focus and exposure
  12. #iwd, #wtm15 Submitting request mCameraCaptureSession.capture(request, new CaptureListener() { @Override public

    void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp) { ... } @Override public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) { ... } }, null);