| class info |
| com.huawei.hms.mlsdk.text.MLTextAnalyzer |
Represents the text analyzer, which detects text (MLText) in an image. There are two types of text analyzers. One is the on-device analyzer, which runs a detection model on the device and returns the detection result. The other is the on-cloud analyzer, which runs a detection model on the cloud after the cloud API is called. An on-device text analyzer can be created using MLAnalyzerFactory.getInstance().getLocalTextAnalyzer() or MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(MLLocalTextSetting settings). The former uses the default configuration, and the latter uses the customized configuration. An on-cloud text analyzer can be created using MLAnalyzerFactory.getInstance().getRemoteTextAnalyzer() or MLAnalyzerFactory.getInstance().getRemoteTextAnalyzer(MLRemoteTextSetting settings). The former uses the default configuration, and the latter uses the customized configuration. |
- // Example of on-device text detection.
- MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer();
- //Create an MLFraMLFramesing the bitmap.
- MLFrame frame = MLFrame.fromBitmap(bitmap);
- // Detect text in an image.
- Task<MLText> task = analyzer.asyncAnalyseFrame(frame);
- task.addOnSuccessListener(new OnSuccessListener<MLText>() {
- @Override
- public void onSuccess(MLText text) {
- // Detection success.
- }
- }).addOnFailureListener(new OnFailureListener() {
- @Override
- public void onFailure(Exception e) {
- // Detection failure.
- }
- });
- // Example of on-cloud text detection.
- MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getRemoteTextAnalyzer();
- //Create an MLFraMLFramesing the bitmap.
- MLFrame frame = MLFrame.fromBitmap(bitmap);
- // Detect text in an image.
- Task<MLText> task = analyzer.asyncAnalyseFrame(frame);
- task.addOnSuccessListener(new OnSuccessListener<MLText>() {
- @Override
- public void onSuccess(MLText text) {
- // Detection success.
- }
- }).addOnFailureListener(new OnFailureListener() {
- @Override
- public void onFailure(Exception e) {
- // Detection failure.
- }
- });
| Type | Name | Desc |
| int | OCR_LOCAL_TYPE | On-device detection mode. |
| int | OCR_REMOTE_TYPE | On-cloud detection mode. |
| Return type | Method name |
| android.util.SparseArray<MLText.Block> | analyseFrame(MLFrame frame) |
| com.huawei.hmf.tasks.Task<MLText> | asyncAnalyseFrame(MLFrame frame) |
| void | close()throws IOException |
| void | stop()throws IOException |
| int | getAnalyseType() |
| boolean | isAvailable() |
| Constant |
| public static final int OCR_LOCAL_TYPE |
On-device detection mode. |
| Constant |
| public static final int OCR_REMOTE_TYPE |
On-cloud detection mode. |
Parameters
| Parameter name | Parameter desc |
| frame | Image to be detected. |
Return
| Type | desc |
| android.util.SparseArray<MLText.Block> | Returns the detected text block information, including the content, language, and text bounding box. |
Parameters
| Parameter name | Parameter desc |
| frame | Image to be detected. |
Return
| Type | desc |
| com.huawei.hmf.tasks.Task<MLText> | Returns the asynchronous task that encapsulates the detection result. |
| Method |
| public void close() throws IOException |
| Releases resources, including input and output streams. |
Throws
| Exception name | Exception desc |
| IOException | Exception that occurs in the input and output streams during resource release. |
| Method |
| public void stop() throws IOException |
| Releases resources, including input and output streams. |
Throws
| Exception name | Exception desc |
| IOException | Exception that occurs in the input and output streams during resource release. |
| Method |
| public int getAnalyseType() |
| Obtains the detection mode. |
Return
| Type | desc |
| int | Returns the detection mode 0: OCR_LOCAL_TYPE, indicating the on-device detection mode 1: OCR_REMOTE_TYPE, indicating the on-cloud detection mode |
| Method |
| public boolean isAvailable() |
| Indicates whether the analyzer is available. |
Return
| Type | desc |
| boolean | true: The analyzer is available. false: The detector is unavailable. |