Text.TextBlock
Stay organized with collections
Save and categorize content based on your preferences.
A block of text (think of it as a paragraph) as deemed by the OCR engine.
Inherited Method Summary
From class java.lang.Object
Object
|
clone()
|
boolean |
|
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 Rect getBoundingBox ()
Returns the axis-aligned bounding rectangle of the detected text. If nothing found,
it returns null
.
public Point[]
getCornerPoints ()
Gets the four corner points in clockwise direction starting with top-left. Due to
the possible perspective distortions, this is not necessarily a rectangle. Parts of the
region could be outside of the image. If nothing found, it returns
null
.
public synchronized List<Text.Line>
getLines ()
Gets an unmodifiable list of Text.Line
s
that make up this text block.
Returns an empty list if nothing is found.
public String getRecognizedLanguage ()
Gets prevailing language in the text, if any. The format is in BCP47 (e.g. "en" or
"sr-Latn-BA") or "und" if the language could not be determined.
public String getText ()
Gets the recognized text in the Text.TextBlock
.
It concatenates text strings from underlying Text.Line
s
separated by '\n'
.
The recognized text is in reading order for the language. For Latin, this is top to
bottom within a TextBlock, and left-to-right within a Line.
Returns an empty string 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.
[null,null,["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eText.TextBlock\u003c/code\u003e represents a paragraph of text identified by the OCR engine.\u003c/p\u003e\n"],["\u003cp\u003eIt provides access to the text content, bounding box, corner points, and recognized language.\u003c/p\u003e\n"],["\u003cp\u003eIt is composed of a list of \u003ccode\u003eText.Line\u003c/code\u003e objects, representing individual lines of text within the block.\u003c/p\u003e\n"],["\u003cp\u003eThe recognized text can be retrieved, and it maintains the reading order of the detected language.\u003c/p\u003e\n"],["\u003cp\u003eYou can obtain the bounding box and corner points to locate the text block within the image.\u003c/p\u003e\n"]]],["The `Text.TextBlock` class represents a paragraph of text detected by an OCR engine. It provides methods to: get the bounding rectangle (`getBoundingBox`), retrieve corner points (`getCornerPoints`), access an unmodifiable list of `Text.Line` objects (`getLines`), determine the prevailing language (`getRecognizedLanguage`), and obtain the recognized text (`getText`). Each method returns null or an empty string/list if nothing is found. Inherited methods are also summarized.\n"],null,["# Text.TextBlock\n\npublic static class **Text.TextBlock** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nA block of text (think of it as a paragraph) as deemed by the OCR engine. \n\n### Public Method Summary\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Rect](//developer.android.com/reference/android/graphics/Rect.html) | [getBoundingBox](/android/reference/com/google/mlkit/vision/text/Text.TextBlock#getBoundingBox())() Returns the axis-aligned bounding rectangle of the detected text. |\n| [Point\\[\\]](//developer.android.com/reference/android/graphics/Point.html) | [getCornerPoints](/android/reference/com/google/mlkit/vision/text/Text.TextBlock#getCornerPoints())() Gets the four corner points in clockwise direction starting with top-left. |\n| synchronized [List](//developer.android.com/reference/java/util/List.html)\\\u003c[Text.Line](/android/reference/com/google/mlkit/vision/text/Text.Line)\\\u003e | [getLines](/android/reference/com/google/mlkit/vision/text/Text.TextBlock#getLines())() Gets an unmodifiable list of [Text.Line](/android/reference/com/google/mlkit/vision/text/Text.Line)s that make up this text block. |\n| [String](//developer.android.com/reference/java/lang/String.html) | [getRecognizedLanguage](/android/reference/com/google/mlkit/vision/text/Text.TextBlock#getRecognizedLanguage())() Gets prevailing language in the text, if any. |\n| [String](//developer.android.com/reference/java/lang/String.html) | [getText](/android/reference/com/google/mlkit/vision/text/Text.TextBlock#getText())() Gets the recognized text in the [Text.TextBlock](/android/reference/com/google/mlkit/vision/text/Text.TextBlock). |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Methods\n--------------\n\n#### public [Rect](//developer.android.com/reference/android/graphics/Rect.html) **getBoundingBox** ()\n\nReturns the axis-aligned bounding rectangle of the detected text. If nothing found,\nit returns `null`. \n\n#### public [Point\\[\\]](//developer.android.com/reference/android/graphics/Point.html)\n**getCornerPoints** ()\n\nGets the four corner points in clockwise direction starting with top-left. Due to\nthe possible perspective distortions, this is not necessarily a rectangle. Parts of the\nregion could be outside of the image. If nothing found, it returns\n`null`. \n\n#### public synchronized [List](//developer.android.com/reference/java/util/List.html)\\\u003c[Text.Line](/android/reference/com/google/mlkit/vision/text/Text.Line)\\\u003e\n**getLines** ()\n\nGets an unmodifiable list of [Text.Line](/android/reference/com/google/mlkit/vision/text/Text.Line)s\nthat make up this text block.\n\nReturns an empty list if nothing is found. \n\n#### public [String](//developer.android.com/reference/java/lang/String.html) **getRecognizedLanguage** ()\n\nGets prevailing language in the text, if any. The format is in BCP47 (e.g. \"en\" or\n\"sr-Latn-BA\") or \"und\" if the language could not be determined. \n\n#### public [String](//developer.android.com/reference/java/lang/String.html) **getText** ()\n\nGets the recognized text in the [Text.TextBlock](/android/reference/com/google/mlkit/vision/text/Text.TextBlock).\nIt concatenates text strings from underlying [Text.Line](/android/reference/com/google/mlkit/vision/text/Text.Line)s\nseparated by `'\\n'`.\n\nThe recognized text is in reading order for the language. For Latin, this is top to\nbottom within a TextBlock, and left-to-right within a Line.\n\nReturns an empty string if nothing is found."]]