We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
GuidesHUAWEI HiAI EngineImage RecognitionAesthetics ScoreDevelopment Guide

Development Guide

App Development

Importing Mandatory Classes

  1. Add the classes related to aesthetic scoring to the project.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import com.huawei.hiai.vision.visionkit.common.Frame;//Load the Frame class.
    2. import com.huawei.hiai.vision.visionkit.common.Video;//Load the video class.
    3. import com.huawei.hiai.vision.visionkit.image.detector.AestheticsScore;//Load the aesthetic engine result class.
    4. import com.huawei.hiai.vision.image.detector.AestheticsScoreDetector;//Load the detector class of aesthetic engine.
    5. import com.huawei.hiai.vision.common.VisionBase;//Load the static class for connecting to the service.
    6. import com.huawei.hiai.vision.common.ConnectionCallback;//Load the callback for connecting to the service.
    7. import com.huawei.hiai.vision.visionkit.image.detector.AEVideoResult;//Load the aesthetic engine video result class.
    8. import com.huawei.hiai.vision.visionkit.image.detector.AEModelConfiguration;
    9. import com.google.gson.Gson;

Developing the Function

  1. Perform initialization by using the VisionBase static class, to obtain a connection to the service.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. VisionBase.init(mContext, new ConnectionCallback(){
    2. @Override
    3. public void onServiceConnect(){
    4. Log.i(LOG_TAG, "onServiceConnect");
    5. }
    6. @Override
    7. public void onServiceDisconnect(){
    8. Log.i(LOG_TAG, "onServiceDisconnect");
    9. }
    10. });
  2. Define the aestheticsScoreDetector instance, and use the context of this app as the input parameter.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. AestheticsScoreDetector aestheticsScoreDetector = new AestheticsScoreDetector(mContext);
  3. Configure engine parameters. If you do not set this parameter, all models are enabled. 1: Enable OSP_MODE; 2: Enable HF_MODE; 3: Enable all.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. AEModelConfiguration aeModelConfiguration = new AEModelConfiguration();
    2. aeModelConfiguration.getDetetcImageConf().setDetectImageMode(3)
    3. aestheticsScoreDetector.setAEModelConfiguration(aeModelConfiguration);
  4. Define VisionImage.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. VisionImage image= null;
  5. Place the Bitmap of the image to be processed in image.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. image = VisionImage.fromBitmap(bitmap);
  6. Define AestheticsScore, the image aesthetics scoring result.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. AestheticsScore outputData = new AestheticsScore();
  7. Call detectImage() to obtain the aesthetic score of an image.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. int resultCode = mAestheticsScoreDetector.detectImage(image, outputData, null);
  8. Call getScore() to get the score.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. float score = aestheticsScores.getScore();
  9. Call getFrameTimeStamp() to obtain the time.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. float timeStamp = aestheticsScores.getFrameTimeStamp();
  10. Call getOSPScores() to obtain sub-dimension scores.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. float ospScore = aestheticsScores.getOSPScores();
  11. Call getHFSCore() to obtain sub-dimension scores.
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. float hfScore = aestheticsScores.getHFSCore();
Search in Guides
Enter a keyword.