Text.Element
Stay organized with collections
Save and categorize content based on your preferences.
Represents a space-separated segment in a line of text (for example, a word in most Latin
languages). If a word is split between two lines by a hyphen, each part is encoded as a
separate Text.Symbol
.
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 float getAngle ()
Gets the angle(in degrees, clockwise is positive, range is [-180, 180]) of the
rotation of the recognized element.
public Rect getBoundingBox ()
Returns the axis-aligned bounding rectangle of the detected text. If nothing found,
it returns null
.
public float getConfidence ()
Gets the confidence of the recognized element.
It is in range [0.0f, 1.0f].
Note that this information will be unavailable (i.e. returns 0) if you're using the
unbundled version of Text Recognition library with an older version of Google Play
services (lower than 22.30.XX).
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 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 synchronized List<Text.Symbol>
getSymbols ()
Gets a unmodifiable list of Text.Symbol
s
that make up this text element. Note that such field is not available for unbundled
versions of Text Recognition library yet.
Returns an empty list if nothing is found.
public String getText ()
Gets the recognized text in the Text.Element
.
The recognized text is in reading order for the language. For Latin, it is
left-to-right.
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.Element\u003c/code\u003e represents a space-separated text segment within a line of text, like a word.\u003c/p\u003e\n"],["\u003cp\u003eEach \u003ccode\u003eText.Element\u003c/code\u003e provides access to its recognized text, bounding box, confidence score, language, and constituent symbols.\u003c/p\u003e\n"],["\u003cp\u003eCorner points and rotation angle information are also available for each detected element.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetSymbols\u003c/code\u003e method allows access to individual characters or symbols that comprise the element.\u003c/p\u003e\n"],["\u003cp\u003eIf a word is hyphenated across lines, it's represented by multiple \u003ccode\u003eText.Symbol\u003c/code\u003e objects within separate \u003ccode\u003eText.Element\u003c/code\u003e instances.\u003c/p\u003e\n"]]],["`Text.Element` represents a text segment, like a word. Key actions include retrieving: the text itself (`getText`), its rotation angle (`getAngle`), bounding rectangle (`getBoundingBox`), confidence level (`getConfidence`), and corner points (`getCornerPoints`). It also provides the prevailing language (`getRecognizedLanguage`) and a list of its component symbols (`getSymbols`). These methods return specific data types such as String, float, Rect, Point[], or a List of Text.Symbols, or null/empty if nothing is found.\n"],null,["# Text.Element\n\npublic static class **Text.Element** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nRepresents a space-separated segment in a line of text (for example, a word in most Latin\nlanguages). If a word is split between two lines by a hyphen, each part is encoded as a\nseparate [Text.Symbol](/android/reference/com/google/mlkit/vision/text/Text.Symbol). \n\n### Public Method Summary\n\n|----------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| float | [getAngle](/android/reference/com/google/mlkit/vision/text/Text.Element#getAngle())() Gets the angle(in degrees, clockwise is positive, range is \\[-180, 180\\]) of the rotation of the recognized element. |\n| [Rect](//developer.android.com/reference/android/graphics/Rect.html) | [getBoundingBox](/android/reference/com/google/mlkit/vision/text/Text.Element#getBoundingBox())() Returns the axis-aligned bounding rectangle of the detected text. |\n| float | [getConfidence](/android/reference/com/google/mlkit/vision/text/Text.Element#getConfidence())() Gets the confidence of the recognized element. |\n| [Point\\[\\]](//developer.android.com/reference/android/graphics/Point.html) | [getCornerPoints](/android/reference/com/google/mlkit/vision/text/Text.Element#getCornerPoints())() Gets the four corner points in clockwise direction starting with top-left. |\n| [String](//developer.android.com/reference/java/lang/String.html) | [getRecognizedLanguage](/android/reference/com/google/mlkit/vision/text/Text.Element#getRecognizedLanguage())() Gets prevailing language in the text, if any. |\n| synchronized [List](//developer.android.com/reference/java/util/List.html)\\\u003c[Text.Symbol](/android/reference/com/google/mlkit/vision/text/Text.Symbol)\\\u003e | [getSymbols](/android/reference/com/google/mlkit/vision/text/Text.Element#getSymbols())() Gets a unmodifiable list of [Text.Symbol](/android/reference/com/google/mlkit/vision/text/Text.Symbol)s that make up this text element. |\n| [String](//developer.android.com/reference/java/lang/String.html) | [getText](/android/reference/com/google/mlkit/vision/text/Text.Element#getText())() Gets the recognized text in the [Text.Element](/android/reference/com/google/mlkit/vision/text/Text.Element). |\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 float **getAngle** ()\n\nGets the angle(in degrees, clockwise is positive, range is \\[-180, 180\\]) of the\nrotation of the recognized element. \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 float **getConfidence** ()\n\nGets the confidence of the recognized element.\n\nIt is in range \\[0.0f, 1.0f\\].\n\nNote that this information will be unavailable (i.e. returns 0) if you're using the\nunbundled version of Text Recognition library with an older version of Google Play\nservices (lower than 22.30.XX). \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 [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 synchronized [List](//developer.android.com/reference/java/util/List.html)\\\u003c[Text.Symbol](/android/reference/com/google/mlkit/vision/text/Text.Symbol)\\\u003e\n**getSymbols** ()\n\nGets a unmodifiable list of [Text.Symbol](/android/reference/com/google/mlkit/vision/text/Text.Symbol)s\nthat make up this text element. Note that such field is not available for unbundled\nversions of Text Recognition library yet.\n\nReturns an empty list if nothing is found. \n\n#### public [String](//developer.android.com/reference/java/lang/String.html) **getText** ()\n\nGets the recognized text in the [Text.Element](/android/reference/com/google/mlkit/vision/text/Text.Element).\n\nThe recognized text is in reading order for the language. For Latin, it is\nleft-to-right.\n\nReturns an empty string if nothing is found."]]