AI Color: Enables One-Tap Coloring for a Black-and-White Photo
Tags: machinelearning, ai, videoeditor
Published: 2022-03-09 03:44:53

Many old photos and films were saved black-and-white, due to the technical limitation of the time when they were shot. How great it is when the dull, time-worn black-and-white image is enlivened with colors! Then the colored image can deliver more details, better pulling at the heartstrings of its audience.
This, luckily, can be realized through a solution from HMS Core Video Editor Kit: AI color. Integrate this capability into your app to offer users the convenient coloring service.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k02vahe37uupbuu0246w.png)
Stunning effect, isn't it? Let's see how to integrate the capability.

## Integration Procedure​
### Preparations
For details, please check the [official document](https://developer.huawei.com/consumer/en/doc/development/Media-Guides/config-agc-0000001101108580?ha_source=hms1).

### Configuring a Video Editing Project
1.Set the app authentication information.
You can set the information through an API key or access token.
Use the [setAccessToken](https://developer.huawei.com/consumer/en/doc/development/Media-References/mediaapplication-0000001149508209#section92907346177) method to set an access token when the app is started. The access token needs to be set only once.

```
MediaApplication.getInstance().setAccessToken("your access token");
```
Use the [setApiKey](https://developer.huawei.com/consumer/en/doc/development/Media-References/mediaapplication-0000001149508209#section171221750121916) method to set an API key when the app is started. The API key needs to be set only once.
```
MediaApplication.getInstance().setApiKey("your ApiKey");
```
2.Set a License ID.
This ID is used to manage your usage quotas, so ensure that the ID is unique.
```
MediaApplication.getInstance().setLicenseId("License ID");
```
3.Initialize the running environment for **HuaweiVideoEditor**.
When creating a video editing project, first create a **HuaweiVideoEditor** object and initialize its running environment. When exiting a video editing project, release the **HuaweiVideoEditor** object.

Create a HuaweiVideoEditor object
```
HuaweiVideoEditor editor = HuaweiVideoEditor.create(getApplicationContext());
```
Specify the position for the preview area
This area renders video images, which is implemented by creating SurfaceView in the fundamental capability SDK. Ensure that the preview area position on your app is specified before creating this area.

```
<LinearLayout  
    android:id="@+id/video_content_layout"  
    android:layout_width="0dp"  
    android:layout_height="0dp"  
    android:background="@color/video_edit_main_bg_color"  
    android:gravity="center"  
    android:orientation="vertical" />
// Specify the preview area position.
LinearLayout mSdkPreviewContainer = view.findViewById(R.id.video_content_layout);

// Set the layout of the preview area.
editor.setDisplay(mSdkPreviewContainer);
```

Initialize the running environment. 
If the license verification fails, [LicenseException](https://developer.huawei.com/consumer/en/doc/development/Media-References/sdk-licenseexception-0000001164593066) will be thrown.
After the HuaweiVideoEditor object is created, it has not occupied any system resource. You need to manually set the time for initializing the running environment of the object. Then, necessary threads and timers will be created in the fundamental capability SDK.

```
try {
        editor.initEnvironment();
   } catch (LicenseException error) {
        SmartLog.e(TAG, "initEnvironment failed: " + error.getErrorMsg());  
        finish();
        return;
   }
```

4.Add a video or image.
Create a video lane and add a video or image to the lane using the file path.
```
// Obtain the HVETimeLine object.
HVETimeLine timeline = editor.getTimeLine();

// Create a video lane.
HVEVideoLane videoLane = timeline.appendVideoLane();

// Add a video to the end of the video lane.
HVEVideoAsset videoAsset = videoLane.appendVideoAsset("test.mp4");

// Add an image to the end of the video lane.
HVEImageAsset imageAsset = videoLane.appendImageAsset("test.jpg");
```

### Integrating the AI Color Capability
Note: This capability supports the image and video. The video size should be less than or equal to 100 MB.

## Result​
![Image description](https://forum.xda-developers.com/attachments/1-gif.5538975/)
This article presents the AI Color capability of Video Editor Kit. For more, check [here](https://developer.huawei.com/consumer/en/hms/huawei-video-editor?ha_source=hms1).