How to Use Theme Tagging Service of Image Kit ?

What is Image Kit ?

Image Kit incorporates smart image editing and design as well as animation capabilities into your app, giving it the power of efficient image content reproduction while providing a better image editing experience for your users.

What is Theme Tagging Service ?

Theme tagging service is a part of Image Kit’s Image Vision SDK. Theme tagging service can be used for detecting objects in images or tagging images for classifying them.

In this article, we are going to talk about how to use the Theme tagging service of Image Vision SDK.

Before the development process, you have to integrate the HMS Core.

To get started on Image Kit follow Integration of Image Kit.

Let’s start

Firstly import the image vision packages.

Theme Tagging Service of Image Kit

Now we have to obtain an ImageVision instance for the theme tagging service.

Obtaining ImageVision instance

Now it’s time to initialize the service.

Note: If you are using other services in Image Kit you can use the same method for initializing the service.

Which Is why I created a Utility.class and returned imageVisionAPI.

In Main Activity

initService

In Utility class :

initService

If the initialization is successful onSuccess method is called. And successCode will be 0.

If the framework initialization fails, the onFailure method is called and an error code is returned.

Now you can ask what is authJson?

Description of authJson parameters

You can find Parameters authJson in your agconnect-services.json except for token.

If you didn’t integrate Account kit into your application you can see how to obtain token from here.

But there is a second approach if you integrated Account Kit into your project.

For detailed information about integration of Account Kit you can check this article:

First, you have to login to your Huawei account:

Login with Huawei ID

When you successfully login get Token in onActivityResult:

onActivityResult

Here is the getToken method from the Utility class:

getToken method for getting access token from huaweiAccount

Congratulations you have successfully obtained the access_token for authJson.

Now we have to construct parameters.

imageBitmap is the image we want to tag.

requestJson parameters :

requestJson

Example requestJson :

taskJson parameters :

taskJson

The important part of taskJson is needObjectList.

When it’s true service will provide us with list of objects in the image with objectlist as JSONArray.

Description of result parameters :

Description of response parameters :

Description of tags parameters :

Now first let's obtain the theme tagging result:

apply Tag to image

Congrats now we are able to get the tags of the images.

But there is one more thing Theme Tagging Service can provide us.

And it’s the Object List of the images.

objectlist

Box parameters of objectlist :

With these box parameters from objectlist we can draw lines around the objects that theme tagging services detected.

To get objectlist we have to add the code below into the applyTag() method.

Here we are also adding borders of detected objects to a list.

Then we are using that list to draw on the image.

To Get the borders of the image we can use the method below

getRectangle from object

Finally, let’s draw the lines on the image.

Here is the result :)

When you no longer need theme tagging service call the imageVisionAPI.stop() to stop the service.

References:

--

--

--

Unity Developer @Huawei

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

QuickShortcutMaker Mod Apk Latest Version 2021

QuickShortcutMaker Mod Apk Latest Version 2021

How to Add Asset Image on appBar as an Action Icon in Flutter

Verify Android App Links on Android 12 with Flutter

Android Jetpack Compose: Theme Made Easy

Why Kotlin has Mutable Collections

Surface View vs View — the differences

How to code Augmented Reality Mobile Application with Android ARCore SDK — Part 2

How Can I Quickly Integrate App Linking of AppGallery Connect into My Android App?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Enes Özdemir

Enes Özdemir

Unity Developer @Huawei

More from Medium

Static and Dynamic libraries

How to build FFmpeg extension for integrating into ExoPlayer

Open API Content Validation Issue on WSO2 APIM

Are Sitecore Containers optimized for disk space?