TextRecognition
Stay organized with collections
Save and categorize content based on your preferences.
Entry point for performing optical character recognition(OCR) on an input image to detect
latin-based characters.
A TextRecognizer
is created via getClient(TextRecognizerOptionsInterface)
. See the code example below.
TextRecognizer textRecognizer = TextRecognition.getClient(TextRecognizerOptionsInterface);
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(...);
Inherited Method Summary
From class java.lang.Object
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\u003eTextRecognition\u003c/code\u003e is an entry point for performing optical character recognition (OCR) on images to detect Latin-based characters.\u003c/p\u003e\n"],["\u003cp\u003eYou create a \u003ccode\u003eTextRecognizer\u003c/code\u003e instance using \u003ccode\u003eTextRecognition.getClient(TextRecognizerOptionsInterface)\u003c/code\u003e and process images with it.\u003c/p\u003e\n"],["\u003cp\u003eInput images for OCR are created from sources like Bitmaps or ByteBuffers, using the \u003ccode\u003eInputImage\u003c/code\u003e class.\u003c/p\u003e\n"],["\u003cp\u003eTo avoid resource leaks, make sure to call \u003ccode\u003eTextRecognizer.close()\u003c/code\u003e when you are finished using the \u003ccode\u003eTextRecognizer\u003c/code\u003e instance.\u003c/p\u003e\n"]]],["`TextRecognition` enables OCR for Latin-based characters. First, obtain a `TextRecognizer` instance using `getClient(TextRecognizerOptionsInterface)`. Next, create an `InputImage` from sources like `Bitmap`. To perform OCR, use `textRecognizer.process(image)`, which returns a `Task\u003cText\u003e`. This task's success/failure is handled via listeners. Remember to call `TextRecognizer.close()` to release resources when the `TextRecognizer` is no longer needed. It also inherits methods such as `clone`, `equals`, `getClass`, and others from the `Object` class.\n"],null,["# TextRecognition\n\npublic class **TextRecognition** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nEntry point 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 [getClient(TextRecognizerOptionsInterface)](/android/reference/com/google/mlkit/vision/text/TextRecognition#getClient(com.google.mlkit.vision.text.TextRecognizerOptionsInterface)). See the code example below. \n\n TextRecognizer textRecognizer = TextRecognition.getClient(TextRecognizerOptionsInterface);\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| static [TextRecognizer](/android/reference/com/google/mlkit/vision/text/TextRecognizer) | [getClient](/android/reference/com/google/mlkit/vision/text/TextRecognition#getClient(com.google.mlkit.vision.text.TextRecognizerOptionsInterface))([TextRecognizerOptionsInterface](/android/reference/com/google/mlkit/vision/text/TextRecognizerOptionsInterface) options) Gets a new instance of [TextRecognizer](/android/reference/com/google/mlkit/vision/text/TextRecognizer) to perform optical character recognition on device with the specified [TextRecognizerOptionsInterface](/android/reference/com/google/mlkit/vision/text/TextRecognizerOptionsInterface). |\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 static [TextRecognizer](/android/reference/com/google/mlkit/vision/text/TextRecognizer)\n**getClient** ([TextRecognizerOptionsInterface](/android/reference/com/google/mlkit/vision/text/TextRecognizerOptionsInterface) options)\n\nGets a new instance of [TextRecognizer](/android/reference/com/google/mlkit/vision/text/TextRecognizer)\nto perform optical character recognition on device with the specified [TextRecognizerOptionsInterface](/android/reference/com/google/mlkit/vision/text/TextRecognizerOptionsInterface).\n\nTo release the resources associated with a TextRecognizer, you need to ensure that\n[TextRecognizer.close()](/android/reference/com/google/mlkit/vision/text/TextRecognizer#close())\nis called on the resulting [TextRecognizer](/android/reference/com/google/mlkit/vision/text/TextRecognizer)\nobject once it will no longer be used."]]