Text

  • Text is a hierarchical representation of texts.

  • Text contains a list of TextBlocks, which contain a list of Lines, which are composed of a list of Elements.

  • TextBlocks represent blocks of text, Lines represent lines of text, Elements represent space-separated segments, and Symbols represent single characters.

  • The getText() method retrieves all recognized text as a single string, and getTextBlocks() retrieves a list of TextBlocks.

public class Text extends Object

A hierarchical representation of texts.

A Text contains a list of Text.TextBlock , and a Text.TextBlock contains a list of Text.Line which is composed of a list of Text.Element .

Nested Class Summary

class Text.Element Represents a space-separated segment in a line of text (for example, a word in most Latin languages).
class Text.Line Represents a line of text.
class Text.Symbol Represents a single symbol in an Text.Element .
class Text.TextBlock A block of text (think of it as a paragraph) as deemed by the OCR engine.

Public Method Summary

String
getText ()
Retrieves all the recognized text in the image.
List<Text.TextBlock>
getTextBlocks ()
Gets an unmodifiable list of Text.TextBlock , which is a block of text and can be further decomposed to a list of Text.Line .

Inherited Method Summary

From class java.lang.Object
Object
clone()
boolean
equals(Object arg0)
void
finalize()
final Class<?>
getClass()
int
hashCode()
final void
notify()
final void
notifyAll()
String
toString()
final void
wait(long arg0, int arg1)
final void
wait(long arg0)
final void
wait()

Public Methods

public String getText ()

Retrieves all the recognized text in the image. It concatenates text strings from underlying Text.TextBlock s separated by '\n'.

Returns an empty string if nothing is found.

public List<Text.TextBlock> getTextBlocks ()

Gets an unmodifiable list of Text.TextBlock , which is a block of text and can be further decomposed to a list of Text.Line .

The recognized text is in reading order for the language. For Latin, this is top to bottom within a Text.TextBlock , and left-to-right within a Text.Line .

Returns an empty list if nothing is found.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024年10月31日 UTC.