Binary Princess
Binary Princess

Reputation: 51

Huawei MLTextAnalyzer cannot detect any text from the Bitmap

I am writing an application where I crop certain part of a camera preview frame before feeding it to MLTextAnalyser.

This is how I instantiate the text analyser:

private val hmsTextRecognizer : MLTextAnalyzer by lazy {
val setting = MLLocalTextSetting.Factory()
    .setOCRMode(MLLocalTextSetting.OCR_DETECT_MODE)
    .setLanguage("en")
    .create()
MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(setting)
}

This is how the bitmap looks like:

enter image description here

This is how I call the analyser:

val result = com.huawei.hmf.tasks.Tasks.await(hmsTextRecognizer.asyncAnalyseFrame(MLFrame.fromBitmap(bitmap)))

Unfortunaltly, I dont get any result, no text is recognised.

On MlKit from Firebase, text is reconized fine.

val inputImage = InputImage.fromBitmap(bitmap, 0)
val result = Tasks.await(gmsTextRecognizer.process(inputImage))
if(result.text.isNotBlank()) {
    Timber.d("GMS scanned raw text: ${result.text}")
}

I am running on a Huawei Mate 30 Pro and I am using

com.huawei.hms:ml-computer-vision-ocr:2.0.1.300

Any idea what I might be doing wrong?

Upvotes: 0

Views: 271

Answers (1)

Ibrahim R Serpici
Ibrahim R Serpici

Reputation: 1076

The possible causes are as follows:

Create the text analyzerMLTextAnalyzer to recognize text in images. You can setMLLocalTextSetting to specify languages that can be recognized. If you do not set the languages, only Latin-based languages can be recognized by default.

// Method 1: Use default parameter settings to configure the on-device text analyzer. Only Latin-based languages can be recognized.

MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer();

// Method 2: Use the customized parameter MLLocalTextSetting to configure the text analyzer on the device.

MLLocalTextSetting setting = new MLLocalTextSetting.Factory()

.setOCRMode(MLLocalTextSetting.OCR_DETECT_MODE)

// Specify languages that can be recognized.

.setLanguage("EN")

.create();

MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(setting);

Your case is Method 2,the program thinks this is English, not Latin-based. But English language is only supported in Cloud, not in Device. So it is failed.

Upvotes: 1

Related Questions