[Huawei Developers] John Wo:
Introduction:

HiAI Image recognition is used to obtain quality ,category and scene of a particular image. This article is giving a brief explanation on Aesthetic Score, Image Category Label and Scene Detection APIs. Here we are using DevEco plugin to configure the HiAI application. To know about the integrate of application via DevEco you can refer the article "HUAWEI HiAI Image Super-Resolution Via DevEco".

Aesthetic Score:

Aesthetic scores provide professional evaluations of images in terms of objective technologies and subjective aesthetic appeal in aspects such as focusing, jitter, deflection, color, and composition based on the Deep Neural Network (DNN). A higher score indicates that the image is more “beautiful”. Here the size of the input image is not greater than 20 megapixel and the standard pixels used in aesthetic scoring is 50176 pixels and returns the result in JSON format.

Example result (JSON):

{"resultCode":0,"aestheticsScore":"{"score":74.33469}"}

private void aestheticScore() {
/** Define AestheticScore class*/
AestheticsScoreDetector aestheticsScoreDetector = new AestheticsScoreDetector(this);
/** Define frame class, and put the picture which need to be scored into the frame： */
Frame frame = new Frame();
frame.setBitmap(bitmap);
/** Note: This line of code must be placed in the worker thread instead of the main thread */
JSONObject jsonObject = aestheticsScoreDetector.detect(frame, null);
/** Call the detect method to get the information of the score */
AestheticsScore aestheticScore = aestheticsScoreDetector.convertResult(jsonObject);
float score = aestheticScore.getScore();
this.score = score;
}

Scene Detection

In scene detection the scene corresponding to the main content of a given image is detected. Here the size of the input image is not greater than 20 megapixel and the image must be of the ARGB888 type and returns the results in JSON format.

Example result (JSON):

{“resultCode”:0,”scene”:”{\”type\”:7}”}.

private void categoryLabelDetector() {

/** 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();
/** BitmapFactory.decodeFile input resource file path*/
// Bitmap bitmap = BitmapFactory.decodeFile(null);
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);
System.out.println("Json:"+jsonLabel);
/** Call convertResult() method to convert the json to java class and get the label detection(you can parse the json by yourself, too) */
Label label = labelDetector.convertResult(jsonLabel);
extracfromlabel(label);
}

Image Category Label

In Image category label, label information of a given images is detected, and the images are categorized according to the label information. Here the size of the input image is not greater than 20 megapixel and is identified based on the deep learning method and returns the result in JSON format.

Example result (JSON):

{"resultCode":0,"label":"{"category":0,"categoryProbability":0.9980469,"labelContent":[{"labelId":0,"probability":0.9980469},{"labelId":45,"probability":0.9345703},{"labelId":89,"probability":0.31835938},{"labelId":24,"probability":0.13061523}],"objectRects":[]}"}

private void sceneDetection() {
/** Define class detector, the context of this project is the input parameter： */
SceneDetector sceneDetector = new SceneDetector(this);
/** define frame class, put the picture which need to be scene detected into the frame */
Frame frame = new Frame();
/** BitmapFactory.decodeFile input resource file path*/
// Bitmap bitmap = BitmapFactory.decodeFile(null);
frame.setBitmap(bitmap);
/** Call the detect method to get the result of the scene detection */
/** Note: This line of code must be placed in the worker thread instead of the main thread */
JSONObject jsonScene = sceneDetector.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) */
Scene scene = sceneDetector.convertResult(jsonScene);
/** Get the identified scene type*/
int type = scene.getType();
if(type<26) {
sceneString = getSceneString(type);
}else{
sceneString="Unknown";
}
System.out.println("Scene:"+sceneString);
}

Screenshot:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/745/226/2640091000001745226.20201023122821.92634113051319642215950494937165:50511105023624:2800:B8ABD1845CF462EC97BA7BFBA49286D4C94AD52C7B68F1819DB79EC87AF6EC4A.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/745/226/2640091000001745226.20201023122821.92634113051319642215950494937165:50511105023624:2800:B8ABD1845CF462EC97BA7BFBA49286D4C94AD52C7B68F1819DB79EC87AF6EC4A.jpg[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/745/226/2640091000001745226.20201023123138.85193565438676262433772979466881:50511105023624:2800:B3601DF5DA85F407E3EE29646B9D55940594F58485382A328016F2BE6E01C50C.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/745/226/2640091000001745226.20201023123138.85193565438676262433772979466881:50511105023624:2800:B3601DF5DA85F407E3EE29646B9D55940594F58485382A328016F2BE6E01C50C.jpg[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/745/226/2640091000001745226.20201023123150.12786878313784665622941763630734:50511105023624:2800:7474EDE9AE405D85E919CD6B58710DDCCCC3949C2D2C4052176D52AB1F5DA804.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/745/226/2640091000001745226.20201023123150.12786878313784665622941763630734:50511105023624:2800:7474EDE9AE405D85E919CD6B58710DDCCCC3949C2D2C4052176D52AB1F5DA804.jpg[/IMG]

Conclusion:

Image Recognition is used in real time scenarios such as automatic photo editing, auxiliary photographing, optimal video cover selection, automatic category-based organization of photos in the album etc. Huawei HiAI Engine supports simultaneous access of multiple users, but does not allow a user to enable multiple threads for calling the same feature.

Reference:

HiAI Guide