目录

  1. // Create an instance of the object analysis configurator.
  2. MLObjectAnalyzerSetting setting = new MLObjectAnalyzerSetting
  3. .Factory()
  4. .allowClassification()
  5. .allowMultiResults()
  6. .setAnalyzerType(MLObjectAnalyzerSetting.SINGLE_IMAGE_MODE)
  7. .create();
  8. // Create an object analyzer without setting parameters.
  9. MLObjectAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocaleObjectAnalyzer();
  10. // Create an object analyzer by setting parameters.
  11. MLObjectAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocaleObjectAnalyzer(setting);
  1. // Create an instance of the object analysis configurator.
  2. MLObjectAnalyzerSetting setting = new MLObjectAnalyzerSetting
  3. .Factory()
  4. .allowClassification()
  5. .allowMultiResults()
  6. .setAnalyzerType(MLObjectAnalyzerSetting.SINGLE_IMAGE_MODE)
  7. .create();
  8. // Create an object analyzer without setting parameters.
  9. MLObjectAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocaleObjectAnalyzer();
  10. // Create an object analyzer by setting parameters.
  11. MLObjectAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocaleObjectAnalyzer(setting);
class info
com.huawei.hms.mlsdk.objects.MLObjectAnalyzer
Represents the object analyzer, which detects object information (MLObject) in an image. You can create an object analyzer in either of the following ways:
1. Set parameters to customize an object analysis configurator.
2. Use the default object analysis configurator without setting parameters. The video stream mode is used by default.

Sample Code

  1. // Create an instance of the object analysis configurator.
  2. MLObjectAnalyzerSetting setting = new MLObjectAnalyzerSetting.Factory()
  3.    .allowClassification()
  4.    .allowMultiResults()
  5.    .setAnalyzerType(MLObjectAnalyzerSetting.TYPE_PICTURE)
  6.    .create();
  7. // Create an object analyzer without setting parameters.
  8. MLObjectAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalObjectAnalyzer();
  9. // Create an object analyzer by setting parameters.
  10. MLObjectAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalObjectAnalyzer(setting);

Public Method Summary

Return typeMethod name
com.huawei.hmf.tasks.Task<List<MLObject>>asyncAnalyseFrame(MLFrame frame)
voidstop() throws IOException

Public Methods

Method
public com.huawei.hmf.tasks.Task<List<MLObject>> asyncAnalyseFrame(MLFrame frame)
Detects objects in a supplied image by asynchronous call.

Parameters

Parameter nameParameter desc
frameImage to be detected.


Return

Typedesc
com.huawei.hmf.tasks.Task<List<MLObject>>Returns the asynchronous task that encapsulates the detection result. For details about the usage, see the sample code.


Sample Code

  1. // Create an object analyzer instance that uses the default configuration.
  2. MLObjectAnalyzerSetting setting = new MLObjectAnalyzerSetting.Factory()
  3.    .allowClassification()
  4.    .allowMultiResults()
  5.    .setAnalyzerType(MLObjectAnalyzerSetting.TYPE_PICTURE)
  6.    .create();
  7. MLObjectAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalObjectAnalyzer(setting);
  8. // Create an MLFrame by using the bitmap.It is recommended that the image size be greater than or equal to 288 x 288.
  9. MLFrame frame = new MLFrame.Creator().setBitmap(bitmap).create();
  10. Task<List<MLObject>> task = analyzer.asyncAnalyseFrame(frame);
  11. task.addOnSuccessListener(new OnSuccessListener<List<MLObject>>() {
  12.    public void onSuccess(List<MLObject> Object) {
  13.        // Processing logic for detection success
  14.    }
  15. }).addOnFailureListener(new OnFailureListener() {
  16.    public void onFailure(Exception e) {
  17.        // Processing logic for detection failure
  18.    }
  19. });
Method


public void stop() throws IOException

Releases resources, including input and output streams.

Throws

Exception nameException desc
IOExceptionI/O exception in input and output streams.