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.
Now we have to obtain an ImageVision instance for the theme tagging service.
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
In Utility class :
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?

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:
When you successfully login get Token in onActivityResult:
Here is the getToken method from the Utility class:
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 :

Example requestJson :
taskJson parameters :

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:
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.

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
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: