Taking photos in HDR mode

Using the Camera C API, you can also take photos in high dynamic range (HDR) mode.

HDR imaging is a process for increasing the dynamic range of a photograph. The dynamic range of a photograph is the difference between the darkest and the brightest areas in the image. The HDR process involves taking multiple photographs in quick succession at different exposure levels and then compositing the photographs for final output.

There are two ways to generate HDR photos:

  • Capture an HDR image in real time
  • Render an HDR image offline

For more information on Camera API functions that support the HDR mode, see Camera Features Library.

Capturing an HDR image in real time

To capture an HDR image in real time, your app creates an HDR session and explicitly binds the session to an open camera handle. This binding allows the HDR session to directly operate the camera and capture the necessary input images to produce an output HDR image. You must configure the camera for exposure bracketing mode before using the HDR module. 

To capture an HDR image, your app needs to:

  1. Set up a camera.
  2. Start the viewfinder in CAMERA_VFMODE_EV_BRACKETING.
  3. Create an HDR session.
  4. Bind the camera to the HDR session.
  5. Trigger an HDR capture.
  6. Clean up the HDR session.

The following code sample highlights the code flow to capture an HDR image in real time. For simplicity, the code doesn't include details such as setting up the camera and defining the callback functions. For a code sample about setting up the camera, see Set up the camera for burst mode. For more information on camera callback functions, see Callbacks.

Not applicable

Not applicable

/* Open a camera and start the viewfinder
   in CAMERA_VFMODE_EV_BRACKETING mode
   ...
 */

/* Create and initialize an HDR session */
result = camera_hdr_create(&hdr_session);
if (result != CAMERA_EOK) {
    /* Handle error */
}

/* Bind the camera to the HDR session */
result = camera_hdr_bind_camera(hdr_session,
                                camera_handle);
if (result != CAMERA_EOK) {
    /* Handle error */
}

/* Trigger an HDR capture */
result = camera_hdr_take_photo(hdr_session,
                               &shutter_callback,
                               NULL,
                               &postview_callback,
                               &image_callback,
                               &unprocessed_image_callback,
                               NULL,
                               (void*)user_arg,
                               false);
if (result != CAMERA_EOK) {
    /* Handle error */
}

/* clean up the HDR session */
result = camera_hdr_destroy(hdr_session);
if (result != CAMERA_EOK) {
    /* Handle error */
}                
            

Rendering an HDR image offline

To render an HDR image offline, your app gives the HDR module a series of input images that are taken at different exposure levels and the HDR module renders an output image. You decide how to acquire the input images.

Offline HDR rendering is useful in use cases where an app requires control over the capture conditions. For example, you can design an app to capture five exposure-bracketed images as input and to provide the user with one of the following options:

  • Render the final HDR image using any three of the five input images
  • Render multiple HDR images for later consideration

To render an HDR image offline, your app needs to:

  1. Obtain access to a number of images that have been taken at different exposure levels.
  2. Create an HDR session.
  3. Add each image to the HDR session.
  4. Render the HDR image.
  5. Save the rendered image.
  6. Free the buffer used by the rendered image.
  7. Clean up the HDR session.

The following code sample uses three acquired images as input to render an HDR image.

Not applicable

Not applicable

camera_hdr_t hdr_session = NULL;
camera_error_t result;
camera_buffer_t* underexposed_image;
camera_buffer_t* normal_image;
camera_buffer_t* overexposed_image;
camera_buffer_t* rendered_image;

/* Acquire three images at different exposure levels */
/* ... */

/* Create and initialize the HDR session */
result = camera_hdr_create(&hdr_session);
if (result != CAMERA_EOK) {
    /* Handle error */
}

/* Add the three images to the HDR session */
result = camera_hdr_add_image_to_session(hdr_session,
                                         &underexposed_image,
                                         -2.0);
if (result != CAMERA_EOK) {
    /* Handle error */
}
result = camera_hdr_add_image_to_session(hdr_session,
                                         &normal_image,
                                         0.0);
if (result != CAMERA_EOK) {
    /* Handle error */
}
result = camera_hdr_add_image_to_session(hdr_session,
                                         overexposed_image,
                                         +2.0);
if (result != CAMERA_EOK) {
    /* Handle error */
}

/* render the HDR image */
result = camera_hdr_render(hdr_session,
                           &rendered_image,
                           CAMERA_HDR_RENDERTYPE_IMAGE);
if (result != CAMERA_EOK) {
    /* Handle error */
}

/* Save the rendered image to disk */
/* ... */

/* Free the rendered image buffer */
result = camera_hdr_free_buffer(rendered_image);
if (result != CAMERA_EOK) {
    /* Handle error */
}

/* Clean up HDR session */
result = camera_hdr_destroy(hdr_session);
if (result != CAMERA_EOK) {
    /* Handle error */
}                
            

Last modified: 2015-05-07



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus