How to Detect Words with TextRecognizer? It can only detect TextBlocks

泄露秘密 提交于 2019-12-11 07:23:49

问题


I am able to detect TextBlock like Cyan color block in below image but I want to detect Word with TextRecogniger


回答1:


If you have a look at the reference (https://developers.google.com/android/reference/com/google/android/gms/vision/text/TextBlock), you will see that in the recognized block you will have a list of lines which has a list of elements.

Then you should get the word in your Processor class with something like this:

@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
    SparseArray<TextBlock> items = detections.getDetectedItems();
    for (int i = 0; i < items.size(); ++i) {
        TextBlock item = items.valueAt(i);
        List<Line> lines = (List<Line>) item.getComponents();
        for (Line line : lines) {
            List<Element> elements = (List<Element>) line.getComponents();
            for (Element element : elements) {
                String word = element.getValue();
            }
        }
    }
}


来源:https://stackoverflow.com/questions/46220141/how-to-detect-words-with-textrecognizer-it-can-only-detect-textblocks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!