Detector for performing optical character recognition(OCR) on an input image.
A text detector is created via
getVisionTextDetector()
. See the code example below.
FirebaseVisionTextDetector textDetector =
FirebaseVision.getInstance().getVisionTextDetector();
To perform OCR on an image, you first need to create an instance of 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 = textDetector.detectInImage(image);
task.addOnSuccessListener(...).addOnFailureListener(...);
Public Method Summary
void |
close()
Closes the text detector and release its model resources.
|
Task<FirebaseVisionText> |
Inherited Method Summary
Public Methods
public void close ()
Closes the text detector and release its model resources.
Throws
IOException |
---|
public Task<FirebaseVisionText> detectInImage (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
.