TextRecognizer
Stay organized with collections
Save and categorize content based on your preferences.
TextRecognition
client for performing optical character recognition(OCR) on an input image to detect
latin-based characters.
A TextRecognizer
is created via
TextRecognition.getClient(TextRecognizerOptionsInterface)
. See the code example
below.
TextRecognizer textRecognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS);
To perform OCR on an image, you first need to create an instance of
InputImage
from a
ByteBuffer
,
Bitmap
, etc. See
InputImage
documentation for more details. For example, the code below creates an
InputImage
from a
Bitmap
.
InputImage image = InputImage.fromBitmap(bitmap, rotationDegrees);
Then the code below can detect texts in the supplied InputImage
.
Task<Text> task = textRecognizer.process(image);
task.addOnSuccessListener(...).addOnFailureListener(...);
Public Method Summary
abstract void |
close()
Closes the detector and releases its resources.
|
abstract Task<Text>
|
process( MlImage
image)
Detects latin-based characters from the supplied image.
|
abstract Task<Text>
|
|
Inherited Method Summary
From interface java.io.Closeable
From interface java.lang.AutoCloseable
Public Methods
public abstract void close ()
Closes the detector and releases its resources.
public abstract Task<Text>
process (MlImage
image)
Detects latin-based characters from the supplied image.
This is an experimental API in beta version.
Create an MlImage
object using one of MlImage
's
builder methods. See MlImage
documentation for more details.
If the text recognition model has not been downloaded yet, the returned
Task
will
contain an MlKitException
with error code MlKitException.UNAVAILABLE
.
Returns
- a
Task
that
asynchronously returns the recognized Text
.
public abstract Task<Text>
process (InputImage
image)
Returns
- a
Task
that
asynchronously returns the recognized Text
.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eTextRecognizer\u003c/code\u003e is a client for performing optical character recognition (OCR) on images to detect Latin-based characters.\u003c/p\u003e\n"],["\u003cp\u003eIt can process images provided as either \u003ccode\u003eInputImage\u003c/code\u003e or \u003ccode\u003eMlImage\u003c/code\u003e objects to extract text.\u003c/p\u003e\n"],["\u003cp\u003eTo use \u003ccode\u003eTextRecognizer\u003c/code\u003e, obtain an instance via \u003ccode\u003eTextRecognition.getClient()\u003c/code\u003e and then call \u003ccode\u003eprocess()\u003c/code\u003e with the image.\u003c/p\u003e\n"],["\u003cp\u003eRemember to close the \u003ccode\u003eTextRecognizer\u003c/code\u003e using \u003ccode\u003eclose()\u003c/code\u003e when finished to release resources.\u003c/p\u003e\n"]]],["The `TextRecognizer` performs optical character recognition (OCR) to detect Latin-based characters in images. To use it, create a `TextRecognizer` instance via `TextRecognition.getClient()`. Then, create an `InputImage` from sources like `Bitmap`. Use `textRecognizer.process(image)` to detect text, which returns a `Task\u003cText\u003e`. The `close()` method releases the detector's resources. The `process()` method takes either `MlImage` or `InputImage` and may return an error if the recognition model is not downloaded.\n"],null,["# TextRecognizer\n\npublic interface **TextRecognizer** implements [Detector](/android/reference/com/google/mlkit/vision/interfaces/Detector)\\\u003c[Text](/android/reference/com/google/mlkit/vision/text/Text)\\\u003e [OptionalModuleApi](/android/reference/com/google/android/gms/common/api/OptionalModuleApi) \n[TextRecognition](/android/reference/com/google/mlkit/vision/text/TextRecognition)\nclient for performing optical character recognition(OCR) on an input image to detect\nlatin-based characters.\n\nA [TextRecognizer](/android/reference/com/google/mlkit/vision/text/TextRecognizer)\nis created via [TextRecognition.getClient(TextRecognizerOptionsInterface)](/android/reference/com/google/mlkit/vision/text/TextRecognition#getClient(com.google.mlkit.vision.text.TextRecognizerOptionsInterface)). See the code example\nbelow. \n\n TextRecognizer textRecognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS);\n \nTo perform OCR on an image, you first need to create an instance of [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage) from a [ByteBuffer](//developer.android.com/reference/java/nio/ByteBuffer.html), [Bitmap](//developer.android.com/reference/android/graphics/Bitmap.html), etc. See [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage) documentation for more details. For example, the code below creates an [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage) from a [Bitmap](//developer.android.com/reference/android/graphics/Bitmap.html). \n\n InputImage image = InputImage.fromBitmap(bitmap, rotationDegrees);\n \nThen the code below can detect texts in the supplied [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage). \n\n Task\u003cText\u003e task = textRecognizer.process(image);\n task.addOnSuccessListener(...).addOnFailureListener(...);\n \n### Public Method Summary\n\n|-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [close](/android/reference/com/google/mlkit/vision/text/TextRecognizer#close())() Closes the detector and releases its resources. |\n| abstract Task\\\u003c[Text](/android/reference/com/google/mlkit/vision/text/Text)\\\u003e | [process](/android/reference/com/google/mlkit/vision/text/TextRecognizer#process(com.google.android.odml.image.MlImage))([MlImage](/android/reference/com/google/android/odml/image/MlImage) image) Detects latin-based characters from the supplied image. |\n| abstract Task\\\u003c[Text](/android/reference/com/google/mlkit/vision/text/Text)\\\u003e | [process](/android/reference/com/google/mlkit/vision/text/TextRecognizer#process(com.google.mlkit.vision.common.InputImage))([InputImage](/android/reference/com/google/mlkit/vision/common/InputImage) image) Detects latin-based characters from the supplied image. |\n\n### Inherited Method Summary\n\nFrom interface java.io.Closeable \n\n|---------------|---------|\n| abstract void | close() |\n\nFrom interface java.lang.AutoCloseable \n\n|---------------|---------|\n| abstract void | close() |\n\nPublic Methods\n--------------\n\n#### public abstract void **close** ()\n\nCloses the detector and releases its resources. \n\n#### public abstract Task\\\u003c[Text](/android/reference/com/google/mlkit/vision/text/Text)\\\u003e\n**process** ([MlImage](/android/reference/com/google/android/odml/image/MlImage) image)\n\nDetects latin-based characters from the supplied image.\n\nThis is an experimental API in beta version.\n\nCreate an [MlImage](/android/reference/com/google/android/odml/image/MlImage)\nobject using one of [MlImage](/android/reference/com/google/android/odml/image/MlImage)'s\nbuilder methods. See [MlImage](/android/reference/com/google/android/odml/image/MlImage)\ndocumentation for more details.\n\nIf the text recognition model has not been downloaded yet, the returned\n[Task](/android/reference/com/google/android/gms/tasks/Task) will\ncontain an [MlKitException](/android/reference/com/google/mlkit/common/MlKitException)\nwith error code [MlKitException.UNAVAILABLE](/android/reference/com/google/mlkit/common/MlKitException#UNAVAILABLE). \n\n##### Returns\n\n- a [Task](/android/reference/com/google/android/gms/tasks/Task) that asynchronously returns the recognized [Text](/android/reference/com/google/mlkit/vision/text/Text). \n\n#### public abstract Task\\\u003c[Text](/android/reference/com/google/mlkit/vision/text/Text)\\\u003e\n**process** ([InputImage](/android/reference/com/google/mlkit/vision/common/InputImage) image)\n\nDetects latin-based characters from the supplied image.\n\nCreate an [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)\nobject using one of [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)'s\nfactory methods. See [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)\ndocumentation for more details.\n\nIf the text recognition model has not been downloaded yet, the returned\n[Task](/android/reference/com/google/android/gms/tasks/Task) will\ncontain an [MlKitException](/android/reference/com/google/mlkit/common/MlKitException)\nwith error code [MlKitException.UNAVAILABLE](/android/reference/com/google/mlkit/common/MlKitException#UNAVAILABLE). \n\n##### Returns\n\n- a [Task](/android/reference/com/google/android/gms/tasks/Task) that asynchronously returns the recognized [Text](/android/reference/com/google/mlkit/vision/text/Text)."]]