[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forum​

Take a photo and automatically get a infromations from the object in there, the scenes presented an behaiviors, this can be very usefull if you need to categorize your images and photos based on deep learning, this is something that we can do with HiAI - category label capability, in this post, you will see how to do it with a JAVA project.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807171751.22650792785700916909263968327144:50510819012900:2800:AE3D4B1832F6515C71390CB0DB28D6F1C2DF71FA5E814FC5BF9F1E1D1296282A.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807171751.22650792785700916909263968327144:50510819012900:2800:AE3D4B1832F6515C71390CB0DB28D6F1C2DF71FA5E814FC5BF9F1E1D1296282A.png[/IMG]

HIAI has serveral categories, base on deep learning you will be able to get a category that is identified in your images.

if you want to get the full information you will get it on the API reference in the next link: https://developer.huawei.com/consumer/en/doc/development/hiai-References/20201004

What do we need :

Java JDK installation package

Android Studio 3.1 or later

Android SDK package

HiAI SDK package

1) Install DevEco IDE Plugins

Into your Android istudio go to File>Settings>Plugins and search for Dev ECO ID and Enable it \m/

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200717165111.88430803503882341598326481661571:50510819012900:2800:41DC7280AF8B539847C0C982D23C21172B0AF6937D1B75B21198714CE47FE980.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200717165111.88430803503882341598326481661571:50510819012900:2800:41DC7280AF8B539847C0C982D23C21172B0AF6937D1B75B21198714CE47FE980.png[/IMG]

Once is enable, dont forget to Restart you IDE (Android Studio).

2) Create your APP

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200717165245.55201428211713371729218839533969:50510819012900:2800:8B0DA258F2D76C05EDFC35D429D52F2DB1CF8AF01AA0316C6B2F6EC5FA4B427D.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200717165245.55201428211713371729218839533969:50510819012900:2800:8B0DA258F2D76C05EDFC35D429D52F2DB1CF8AF01AA0316C6B2F6EC5FA4B427D.png[/IMG]

3) Add dependency library

· Download the Huawei-hiai-vision.aar package in the Huawei AI Engine SDKs from the Huawei developer community.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200717165351.07196417127694371820275381450706:50510819012900:2800:F33AD138596DE2FDE62D932028E75988B0F87B75FAA7E17255F3859A2DE7B357.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200717165351.07196417127694371820275381450706:50510819012900:2800:F33AD138596DE2FDE62D932028E75988B0F87B75FAA7E17255F3859A2DE7B357.png[/IMG]

· Copy the downloaded vision-release.aar package to the app/libs directory of the project.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200731162352.86874326243820616979061766408941:50510819012900:2800:EDB7D1D42CA8E9A31C1B54EC23BE45C9335E75BC2DBFFD18F89845AFA5C4ECB7.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200731162352.86874326243820616979061766408941:50510819012900:2800:EDB7D1D42CA8E9A31C1B54EC23BE45C9335E75BC2DBFFD18F89845AFA5C4ECB7.png[/IMG]

4) Lets code

I will create a project on android studio starting with an empty activity, for the visual side i will add an imageView to show the photo, a button to take the photo and a textview to show the different value sthat i can get for the category from HIAI, for the logic side i will use the HiAi methods to make the API call to get the Category Label of the photos, the steps that we need are the following:

-Define the layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.CategoryLabel">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintlayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintVertical_bias="0.5"
app:layout_constraintBottom_toTopOf="@+id/linearlayout">

<com.huawei.hiaicodedemo.widget.TitleBar
android:id="@+id/titleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleName="@string/as_catLabel"
app:titleTextColor="@color/black"
app:titleTextSize="18sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>

<ImageView
android:id="@+id/text_origin"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="30dp"
android:src="@color/color_6e"
app:layout_constraintDimensionRatio="h,4:3"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintWidth_percent="0.8"
app:layout_constraintTop_toBottomOf="@+id/titleBar"
app:layout_constraintBottom_toTopOf="@+id/after"/>

<LinearLayout
android:id="@+id/after"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="15dp"
android:text="@string/as_result"
android:textSize="18sp"/>

<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/color_6e"/>

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

<LinearLayout
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/color_6e"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintVertical_bias="0.5"
app:layout_constraintTop_toBottomOf="@+id/constraintlayout">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">

<androidx.core.widget.NestedScrollView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="h,4:3"
app:layout_constraintWidth_percent="0.8"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:background="@color/color_6e">

<EditText
android:id="@+id/text_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:textColor="@color/black" />
</androidx.core.widget.NestedScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:id="@+id/takePhoto"
android:layout_width="90dp"
android:layout_height="37dp"
android:layout_marginStart="48dp"
android:layout_marginTop="16dp"
android:background="@drawable/submit_button"
android:text="@string/foto"
android:textAllCaps="false"
android:textColor="@drawable/submit_button_text_color"
android:textSize="15sp"
app:layout_constraintHorizontal_bias="0.031"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/btn_album"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.37" />

</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807173209.23274569928828075983493963004664:50510819012900:2800:5353CCA8CB988F9FE12D6C2F65CCA540188E2BE0480DB52B5736DCA871C4979C.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807173209.23274569928828075983493963004664:50510819012900:2800:5353CCA8CB988F9FE12D6C2F65CCA540188E2BE0480DB52B5736DCA871C4979C.png[/IMG]

-Prepare the intent to get the picture from the camera and save it into a Bitmap

public void tomaFotoCategory(CategoryLabel view){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_FOTO);
}

Remember to add the permises to use the periferic in you manifest:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

-Connect to HiAi Engine to use the Category Label using VisionBase Class

private void initHiAI() {
VisionBase.init(this, new ConnectionCallback() {
@Override
public void onServiceConnect() {
}
@Override
public void onServiceDisconnect() {
}
});
}

-Make the API CALL to get the Category Label, for this you need to declare a variable Frame & Label where you will get the response from the method

/** Define class detector, the context of this project is the input parameter*/
LabelDetector labelDetector = new LabelDetector(this);
/**Define the frame, put the bitmap that needs to detect the image into the frame*/
Frame frame = new Frame();
frame.setBitmap(bitmap);
/** Call the detect method to get the result of the label detection */
/** Note: This line of code must be placed in the worker thread instead of the main thread*/
JSONObject jsonLabel = labelDetector.detect(frame, null);
/** Call convertResult() method to convert the json to java class and get the label detection(you can parse the json by yourself, too) */
Label label1 = labelDetector.convertResult(jsonLabel);

this.label = label1.getCategory();
this.labelContents =label1.getLabelContent();
this.categoria=label1.getCategory();
this.prob=label1.getCategoryProbability();
handler.sendEmptyMessage(AESTHETICSCORE_RESULT);

-To print the result into the text i will use the getters of all the values that i can get form the object Label, LabelContents, Category anf probablillity:

textEdit.setText("Label: "+String.valueOf(label)
+" \n Categoria: "+categoria
+" \n Label_ID: "+labelContents.get(0).getLabelId()
+" \n Prob: "+ String.valueOf(prob)
+" \n Probabilidad: "+labelContents.get(0).getProbability());

If you need the complete code project, let me know, in there you will be able to review all the parameter definition :).

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807174919.34790615848535117385026057813122:50510819012900:2800:F830CC3C73D67516C62511EE65531EE58910ADB6112B3F4C90C0A1D22E159D40.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807174919.34790615848535117385026057813122:50510819012900:2800:F830CC3C73D67516C62511EE65531EE58910ADB6112B3F4C90C0A1D22E159D40.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807174945.97066078374196612466908240216087:50510819012900:2800:856F5EE50BF2D8B9936309378E5AC2CBACA4F140C97C0194A3A35F262CE99137.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807174945.97066078374196612466908240216087:50510819012900:2800:856F5EE50BF2D8B9936309378E5AC2CBACA4F140C97C0194A3A35F262CE99137.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807175045.06733442978750223123162977092539:50510819012900:2800:CE6371821EC80646F1ECE4BC313FE8183410B01920B86E6437501DF4ED5FC241.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807175045.06733442978750223123162977092539:50510819012900:2800:CE6371821EC80646F1ECE4BC313FE8183410B01920B86E6437501DF4ED5FC241.png[/IMG]

1) Once you have your DevEco IDE plugin Eneable you will see an AMAZING KIT ASSITANT

go to DevECO>EMUI KIT>KIT ASSITANT

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200619180735.63441073705736675412508171806240:50510819012900:2800:34E806FE8967F5E543F31BDB3AAD09A98FD5769971F8ACDCACA0D8D44EA82DF4.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200619180735.63441073705736675412508171806240:50510819012900:2800:34E806FE8967F5E543F31BDB3AAD09A98FD5769971F8ACDCACA0D8D44EA82DF4.png[/IMG]

2) You will see a Menu like this:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200619180817.16285288131275103000237741521565:50510819012900:2800:6DD83188D48D363C7C0605E7366A489E92324F23801C779C02C21BC01CAC7C7F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200619180817.16285288131275103000237741521565:50510819012900:2800:6DD83188D48D363C7C0605E7366A489E92324F23801C779C02C21BC01CAC7C7F.png[/IMG]

3) Select HiAi and look Aesthetic

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200731183707.33866241713584470650687715781392:50510819012900:2800:A045535E41F79F4F868FFC97C993B0867B967DC59E0EE3E3473C3CA4F6E9446B.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200731183707.33866241713584470650687715781392:50510819012900:2800:A045535E41F79F4F868FFC97C993B0867B967DC59E0EE3E3473C3CA4F6E9446B.png[/IMG]

4) BOOM!!! Code Samples, Descriptions, Suggestions, DRAG & DROP CODE!!!!

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807175202.85570430660405523285935394818115:50510819012900:2800:9046E62683D542433356B02C67B42F309C4A687923B019BC3576C14C9E642C3A.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/187/997/2640052000002187997.20200807175202.85570430660405523285935394818115:50510819012900:2800:9046E62683D542433356B02C67B42F309C4A687923B019BC3576C14C9E642C3A.png[/IMG]

Original link: https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201322052049010285&fid=0101187876626530001