首页 > 解决方案 > 华为 HIAI 引擎“通用文本识别”未检测到图像中的任何文本

问题描述

当使用 HIAI Engine 的“通用文本识别”时,我无法让它检测并返回任何文本。例如,对于示例图像,它返回空文本但代码为 200。我使用了 HIAI 文档中的示例程序,所以我不知道问题出在哪里。所以我从头开始创建了另一个应用程序,结果是一样的。

对示例应用程序中提供的图像使用常规文本识别后的日志 来自定制应用程序的日志,仍然是相同的结果

标签: javaandroidartificial-intelligencehuawei-mobile-serviceshuawei-hiai

解决方案


I have figured something out, at least enough to make it work. Some of the images you are importing might be too large, and it throws a code 200, invalid format IE, the image height and width is too large. You will need to check if the height of the bitmap is over 2560 pixels and if the width is over 1440 and scale/crop it accordingly.

What I did:

Bitmap initClassifiedImg;
    if(bitmap.getHeight()>2560 && bitmap.getWidth()>1440)
        initClassifiedImg = Bitmap.createScaledBitmap(bitmap, 1440, 2560, true);
    else if(bitmap.getHeight()>2560)
        initClassifiedImg = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), 2560, true);
    else if (bitmap.getWidth()>1440)
        initClassifiedImg = Bitmap.createScaledBitmap(bitmap, 1440, bitmap.getHeight(), true);
    else
        initClassifiedImg = Bitmap.createBitmap(bitmap);

Set this up to check for the bitmap and it should at the very least not generate a code 200 error Do note that certain images will still fail to generate results. If the resultcode is 0 with no result, that means it just isn't recognizing the text in the image.

Recognition image output example

Sample image output

No result example log


推荐阅读