Text recognizer for performing optical character recognition(OCR) on an input image.
A text recognizer is created via
getOnDeviceTextRecognizer()
or
getCloudTextRecognizer()
. See the code example below.
To use on-device text recognizer:
FirebaseVisionTextRecognizer textRecognizer =
FirebaseVision.getInstance().getOnDeviceTextRecognizer();
FirebaseVisionTextRecognizer textRecognizer =
FirebaseVision.getInstance().getCloudTextRecognizer();
FirebaseVisionImage
from a ByteBuffer
,
Bitmap
,
etc. See FirebaseVisionImage
documentation for more details. For example, the code below creates a FirebaseVisionImage
from a Bitmap
.
FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
Then the code below can detect texts in the supplied FirebaseVisionImage
.
Task
<FirebaseVisionText> task = textRecognizer.processImage(image);
task.addOnSuccessListener(...).addOnFailureListener(...);
Nested Class Summary
@interface | FirebaseVisionTextRecognizer.RecognizerType | Recognizer types. |
Constant Summary
int | CLOUD | Indicates that the recognizer is using a cloud model. |
int | ON_DEVICE | Indicates that the recognizer is using an on-device model. |
Public Method Summary
void |
close()
Closes the text detector and release its model resources.
|
int |
getRecognizerType()
Gets recognizer type in terms of on-device or cloud.
|
Task<FirebaseVisionText> |
Inherited Method Summary
Constants
public static final int CLOUD
Indicates that the recognizer is using a cloud model.
public static final int ON_DEVICE
Indicates that the recognizer is using an on-device model.
Public Methods
public void close ()
Closes the text detector and release its model resources.
Throws
IOException |
---|
public int getRecognizerType ()
Gets recognizer type in terms of on-device or cloud.
public Task<FirebaseVisionText> processImage (FirebaseVisionImage image)
Detects FirebaseVisionText
from a
FirebaseVisionImage
. The OCR is performed asynchronously. Right now, only
the following input types are supported:
For best efficiency, create a
FirebaseVisionImage
object using one of the following ways:
fromMediaImage(Image, int)
with aYUV_420_888
formatted image fromandroid.hardware.camera2
.fromByteArray(byte[], FirebaseVisionImageMetadata)
with aNV21
formatted image fromCamera
(deprecated).fromByteBuffer(ByteBuffer, FirebaseVisionImageMetadata)
if you need to pre-process the image. E.g. allocate a directByteBuffer
and write processed pixels into theByteBuffer
.
FirebaseVisionImage
factory methods will work as well, but possibly slightly
slower.
Returns
- A
Task
forFirebaseVisionText
.