目录

class info
com.huawei.hms.mlplugin.card.gcr.MLGcrCapture
Represents the general card recognition class.

Public Method Summary

Return typeMethod name
voidcaptureImage(android.graphics.Bitmap bitmap, Object object, MLGcrCapture.Callback callback)
voidcapturePhoto(android.content.Context context, Object object, MLGcrCapture.Callback callback)
voidcapturePreview(android.content.Context context, Object object, MLGcrCapture.Callback callback)

Public Methods

Method
public void captureImage(android.graphics.Bitmap bitmap, Object object, MLGcrCapture.Callback callback)
Enables the plug-in for recognizing static images of general cards.

Parameters

Parameter nameParameter desc
bitmapStatic image.
objectReserved.
callbackRecognition result callback.

Sample Code

  1. // Create a general card recognition configurator.
  2. MLGcrCaptureConfig config = new MLGcrCaptureConfig.Factory().create();
  3. MLGcrCapture ocrManager = MLGcrCaptureFactory.getInstance().getGcrCapture(config);
  4. ocrManager.captureImage(bitmap, object, callback);
Method
public void capturePhoto(android.content.Context context, Object object, MLGcrCapture.Callback callback)
Enables the plug-in for taking a photo of a general card and recognizing the general card on the photo.

Parameters

Parameter nameParameter desc
contextActivity or application context.
objectReserved.
callbackRecognition result callback.

Sample Code

  1. // Create a general card recognition configurator.
  2. MLGcrCaptureConfig cardConfig = new MLGcrCaptureConfig.Factory().create();
  3. // Create a general card recognition UI configurator.
  4. MLGcrCaptureUIConfig uiConfig = new MLGcrCaptureUIConfig.Factory()
  5.     // Set the color of the scanning box.
  6.     .setScanBoxCornerColor(Color.GREEN)
  7.     // Set the tip text in the scanning box. It is recommended that the tip text contain fewer than 30 characters.
  8.     .setTipText("Recognizing, align edges")
  9.     // Set the screen orientation. Three modes are supported.
  10.      // MLGcrCaptureUIConfig.ORIENTATION_AUTO: adaptive mode. The physical sensor decides the screen orientation.
  11.     // MLGcrCaptureUIConfig.ORIENTATION_LANDSCAPE: landscape mode. The screen width is greater than the screen height.
  12.      // MLGcrCaptureUIConfig.ORIENTATION_PORTRAIT: portrait mode. The screen height is greater than the screen width.
  13.     .setOrientation(MLGcrCaptureUIConfig.ORIENTATION_AUTO)
  14.     .create();
  15. // Method 1: Create a general card recognition processor based on the customized card recognition UI configurator.
  16. MLGcrCapture ocrManager = MLGcrCaptureFactory.getInstance().getGcrCapture(cardConfig, uiConfig);
  17. // Method 2: Create a general card recognition processor using the default UI.
  18. MLGcrCapture ocrManager = MLGcrCaptureFactory.getInstance().getGcrCapture(cardConfig);
  19. // Bind the general card recognizer and the recognition result callback method.
  20. ocrManager.capturePhoto(this, object, callback);
Method
public void capturePreview(android.content.Context context, Object object, MLGcrCapture.Callback callback)
Enables the plug-in for recognizing general cards in camera streams.

Parameters

Parameter nameParameter desc
contextActivity or application context.
objectReserved.
callbackRecognition result callback.

Sample Code

  1. // Create a general card recognition configurator.
  2. MLGcrCaptureConfig cardConfig = new MLGcrCaptureConfig.Factory().create();
  3. // Create a general card recognition UI configurator.
  4. MLGcrCaptureUIConfig uiConfig = new MLGcrCaptureUIConfig.Factory()
  5.     // Set the color of the scanning box.
  6.     .setScanBoxCornerColor(Color.GREEN)
  7.     // Set the tip text in the scanning box. It is recommended that the tip text contain fewer than 30 characters.
  8.     .setTipText("Recognizing, align edges")
  9.     // Set the screen orientation. Three modes are supported.
  10.      // MLGcrCaptureUIConfig.ORIENTATION_AUTO: adaptive mode. The physical sensor decides the screen orientation.
  11.     // MLGcrCaptureUIConfig.ORIENTATION_LANDSCAPE: landscape mode. The screen width is greater than the screen height.
  12.      // MLGcrCaptureUIConfig.ORIENTATION_PORTRAIT: portrait mode. The screen height is greater than the screen width.
  13.     .setOrientation(MLGcrCaptureUIConfig.ORIENTATION_AUTO)
  14.     .create();
  15. // Method 1: Create a general card recognizer based on the customized card recognition UI configurator.
  16. MLGcrCapture ocrManager = MLGcrCaptureFactory.getInstance().getGcrCapture(cardConfig, uiConfig);
  17. // Method 2: Create a general card recognizer using the default UI.
  18. MLGcrCapture ocrManager = MLGcrCaptureFactory.getInstance().getGcrCapture(cardConfig);
  19. // Bind the general card recognizer and the recognition result callback method.
  20. ocrManager.capturePreview(this, object, callback);