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

1.3k views Asked by At

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

1

There are 1 answers

1
joe On

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();
            }
        }
    }
}