HMS Camera Engine

Önder
Huawei Developers
Published in
8 min readOct 22, 2020

Hello everyone, in this blog I will explain to you what Camera Engine is and how it is used.

What Is Camera Engine?

Everyone wants to keep memories in their best moments, special moments, with their family and friends. Nowadays, most of the people have smart phones and they can easily save the moments by taking photos and videos.

Camera Engine provides apps with the same photographing capabilities as those of Huawei phone cameras. So, camera features such as Wide Aperture, Portrait Mode, HDR, Background Blur, and Super Night mode can help your users shoot stunning images and vivid videos anytime and anywhere to save memories with quality.

Camera Engine is fully compatible with EMUI 10.0 and supports Android and Huawei operating systems.

How It Works?

Camera Engine offers an SDK with preset camera modes. It encapsulates the Google Camera2 API to support multiple enhanced camera capabilities.

1. Front Camera HDR

In a backlit or low-light environment, front camera High Dynamic Range (HDR) improves the details in both the well-lit and poorly-lit areas of photos to present more life-like qualities.

2. Super Night Mode

This mode is used for you to take photos with sufficient brightness by using a long exposure at night. It also helps you to take photos that are properly exposed in other dark environments.

3. Wide aperture

This mode blurs the background and highlights the subject in a photo. You are advised to be within 2 meters of the subject when taking a photo and to disable the flash in this mode.

4. Recording

This mode helps you record HD videos with effects such as different colors, filters, and AI film.

5. Portrait

This mode helps you record portraits and close-ups.

6. Photo Mode

This mode supports the general capabilities that include but are not limited to:

Rear camera: Flash, color modes, face/smile detection, filter, and master AI.

Front camera: Face/Smile detection, filter, SensorHdr, and mirror reflection.

7. Super Slow-mo Recording

This mode allows you to record super slow-motion videos with a frame rate of over 960 FPS in manual or automatic (motion detection) mode.

8. Slow-mo Recording

This mode allows you to record slow-motion videos with a frame rate lower than 960 FPS.

9. Pro Mode (Video)

The Pro mode is designed to open the professional photography and recording capabilities of the Huawei camera to apps to meet diversified shooting requirements.

9.1. Frame rate adjustment capability: CONTROL_AE_TARGET_FPS_RANGE

During video recording, the frame rate can be adjusted from 12 to 60 FPS, based on product specifications.

It provides you to use professional shooting methods such as time-lapse photography or shooting at higher-than-normal frame rates.

Lower frame rates are also supported to achieve slower shutter speeds. When the frame rate is low, the shutter speed is low, allowing for video shooting with artistic effects such as smearing.

You can also record videos with a frame rate of 60 FPS to capture more details compared with 30 FPS videos.

9.2. TONEMAPPING adjustment capability: TONEMAP_MODE and TONEMAP_CURVE

Video recording curve adjustment is supported to offer more options of the video tone.

9.3. Color temperature and tint adjustment capability: COLOR_CORRECTION_MODE and COLOR_CORRECTION_GAINS

The recording color temperature and tint can be adjusted, providing the capability for manually adjusting the white balance and tint.

You can set RGB parameters to adjust the color temperature, ensuring the accuracy of white balance.

You can adjust the color tint to achieve richer video color effects.

10. Pro Mode (Photo)

This mode allows you to adjust the following camera parameters to obtain the same shooting capabilities as those of Huawei camera: Metering mode, ISO, exposure compensation, exposure duration, focus mode, and automatic white balance.

Development Process

First, we register and sign in to Huawei Developer website. Then, we download Camera Engine SDK. When you download the SDK, the system prompts you to sign in and sign the HUAWEI Media Service Usage Agreement.

As environment:

  • Android Studio v3.0.1 or later is recommended.
  • Huawei phones equipped with Kirin 980 or later and running EMUI 10.0 or later are required.

After we create a project with empty activity, we configure build.gradle files.

Then, we are ready to implement Camera Engine features.

Overview

  • Mode Creation

Create a Camera Kit mode when an app is started and the preview view is available.

  • Mode Configuration

Based on the mode features and service requirements, you configure the mode data and status listeners and the preview surface, and set photographing parameters.

  • Mode-based Operations

Starting the Preview: The preview is started when the mode configuration success is returned using the mode status callback.

Setting Functional Parameters:

Using the Mode to Take Photos: Tap on the UI to take a photo in the current mode.

  • Callback Operations

Mode Status Callback: Used to switch the mode creation status and control processes.

Action Data Callback: Used to asynchronously process action data. For example, this callback is used to notify the app that a JPEG image is generated after photographing.

Action Status Callback: Used to asynchronously process action status, for example, photographing starting or stopping.

Mode Resource Release: When an app exits, the resources occupied by the mode are released.

Mode Development Procedure

  • Front Camera HDR Mode Development

Only set mCurrentModeType to Mode.Type.HDR_MODE. Other steps are similar to the steps for developing a common mode.

  • Super Night Mode Development

Set mCurrentModeType to Mode.Type.SUPER_NIGHT_MODE.

The differences from common mode are as follows:

After the preview is started, set the sensitivity and exposure time to adjust an app UI. If the two parameters are not set, the default sensitivity and exposure time are used.

Call the API for stopping photographing after photographing is complete.

Used to asynchronously process action status, for example, photographing starting or stopping.

  • Ultra-wide Angle Mode Development

Set mCurrentModeType to Mode.Type.BOKEH_MODE.

The differences from common mode are as follows:

After the preview is started, set aperture parameters to adjust the ultra-wide angle level.

  • Recording Mode Development

Set mCurrentModeType to Mode.Type.VIDEO_MODE.

The differences from common mode are as follows:

Based on the mode features and service requirements, you configure the mode data and status listeners and the preview surface, and set photographing parameters.

After the preview is started, query and configure the supported features.

After the preview is started, call the recording API.

  • Portrait Mode Development

Set mCurrentModeType to Mode.Type.PORTRAIT_MODE.

Configure the portrait mode after the preview is started.

  • Normal Mode Development

Set mCurrentModeType to Mode.Type.NORMAL_MODE.

You can configure the photographing capability after the preview is enabled.

1) Normal mode supports AI scene identification.

2) Burst shooting with the rear camera is supported in Normal mode.

Or

  • Super Slow-mo Recording Development

Set mCurrentModeType to Mode.Type.SUPER_SLOW_MOTION.

The differences in mode configuration procedure are as follows. Other steps are similar to the steps for general mode.

These two configuration items must be set in pairs based on the Map returned by modeCharacteristics.getSupportedVideoSizes().

Photographing is not supported in Super slow-mo mode. Therefore, no photographing-related configuration should be added.

The video resolution must be the same as the preview resolution.

Different mode operations are as follows:

To start recording:

If the manual recording mode is required, call mMode.startRecording(file) directly to complete a recording task. The recording cannot be stopped halfway. Otherwise, the recording fails.

To have Super slow-mo work in automatic mode, deliver a motion detection frame first:

The detection frame must be a rectangular frame transformed to the central coordinate system from the preview coordinate system. Otherwise, it cannot be delivered.

If the rectangular frame is valid, the module works in automatic mode, and mMode.startRecording(file) is called. Before a moving object is detected, that is, before RecordingResult.State.RECORDING_STARTED is returned, you can call mMode.stopRecording() to stop recording. Once a moving object is detected, recording cannot be stopped. Otherwise, the recording fails.

In automatic mode, the delivered detection area is not saved. After the recording is performed once, the working mode is switched to manual mode. If you want to perform automatic recording again, deliver the detection area again.

In addition, Super-slow mode supports:

Rear camera: flash, zoom, and autoFocus.

Front camera: The front camera does not support Super slow-mo.

  • Slow-mo Recording Development

Set mCurrentModeType to Mode.Type.SLOW_MOTION_MODE.

Except for the steps listed below, other steps are the same as those in normal recording mode.

Slow-mo mode does not support photographing. Therefore, no photographing-related configuration should be added.

Slow-mo mode does not support pause and resume operations during video recording.

In addition, Slow-mo mode supports:

Rear camera: flash, zoom, autoFocus, color mode, and facial recognition.

Front camera: The front camera does not support Slow-mo.

  • Pro Mode Development

1. Set mCurrentModeType to PRO_PHOTO_MODE or PRO_VIDEO_MODE.

2. Use mCurrentModeType to create a Mode object.

3. Call the setParameter method of the Mode object to enable the corresponding capability.

4. Use the takePicture, startRecording, and stopRecording methods of the Mode object to take photos and record videos.

The differences are as follows:

After the preview function is enabled, you can configure the capability values of Pro mode, such as the ISO, exposure time, and white balance.

The settings of other parameters are similar. For ISO and exposure duration, the value 0 can be delivered to enable automatic mode.

Pro mode does not support the front camera or burst shooting.

In addition, Pro mode supports:

Rear camera: flash, zoom, autoFocus, color mode, and facial recognition.

Front camera: The front camera does not support Pro mode.

To take a photo in RAW format, use getSupportedCaptureSizes(ImageFormat.RAW_SENSOR) of ModeCharacteristics to query the supported resolution, select the resolution captureSize, and call addCaptureImage(captureSize,ImageFormat.RAW_SENSOR) of ModeConfig.Builder to set the surface of the RAW image.

  • Pro Video Mode Development

Set mCurrentModeType to Mode.Type.PRO_VIDEO_MODE.

Except for the steps listed below, other steps are the same as those in normal recording mode.

Pro video mode does not support the front camera or burst shooting.

After the preview function is enabled, call the recording API.

The delivery of parameters in Pro recording mode is similar to that in Pro shooting mode. The difference is that there is no parameter for setting the exposure duration in Pro video mode.

In addition, Pro video mode supports:

Rear camera: flash, zoom, autoFocus, color mode, and facial recognition.

Front camera: The front camera does not support Pro video mode.

With all these features, it is provided a set of advanced programming APIs for you to integrate powerful image processing capabilities of Huawei phone cameras into your apps.

References

https://developer.huawei.com/consumer/en/CameraKit

--

--