Search code examples
androidgoogle-visionandroid-vision

TextRecognizer can only detect TextBlocks


I started out by following the Text API tutorial to detect TextBlocks, which worked fine. But I now want to detect text lines, and encountered a problem.

// TODO: Create the TextRecognizer
TextRecognizer textRecognizer = new TextRecognizer.Builder(context).build();

// TODO: Set the TextRecognizer's Processor.
textRecognizer.setProcessor(new OcrDetectorProcessor(mGraphicOverlay));

textRecognizer.setProcessor can only use TextBlock. Is there any way for it to detect lines?


Solution

  • The solution I came up with, going from Pedro Madeira's answer, was this:

        List<? extends Text> textComponents = mText.getComponents();
        for (Text currentText : textComponents) {
            RectF rect = new RectF(currentText.getBoundingBox());
            rect.left = translateX(rect.left);
            rect.top = translateY(rect.top);
            rect.right = translateX(rect.right);
            rect.bottom = translateY(rect.bottom);
            canvas.drawRect(rect, sRectPaint);