Recognizes barcodes (in a variety of 1D and 2D formats) in a supplied FirebaseVisionImage.
A barcode detector is created via
getVisionBarcodeDetector(FirebaseVisionBarcodeDetectorOptions) or
getVisionBarcodeDetector(). The default option is not recommended because it tries
to detect all barcode formats, which is slow. For example, the code below creates a barcode
detector for
FORMAT_PDF417.
FirebaseVisionBarcodeDetector barcodeDetector =
FirebaseVision.getInstance().getVisionBarcodeDetector(
new FirebaseVisionBarcodeDetectorOptions.Builder()
.setBarcodeFormats(FirebaseVisionBarcode.FORMAT_PDF417)
.build());
To perform barcode detection in an image, you first need to create an instance of
FirebaseVisionImage
from a Bitmap,
ByteBuffer, etc. See
FirebaseVisionImage
documentation for more details. For example, the code below creates a FirebaseVisionImage
from a Image.
FirebaseVisionImage image =
FirebaseVisionImage.fromMediaImage(mediaImage, ImageFormat.YUV_420_888);
Then the code below can detect barcodes in the supplied FirebaseVisionImage.
Task<List<FirebaseVisionBarcode>> task = barcodeDetector.detectInImage(image);
task.addOnSuccessListener(...).addOnFailureListener(...);
| void |
close()
Closes this
FirebaseVisionBarcodeDetector and releases its model.
|
| Task<List<FirebaseVisionBarcode>> |
Closes this
FirebaseVisionBarcodeDetector and releases its model.
| IOException |
|---|
Detects barcodes from the supplied image.
For best efficiency, create a
FirebaseVisionImage object using one of the following ways:
fromMediaImage(Image, int) with a YUV_420_888
formatted image from android.hardware.camera2.
fromByteArray(byte[], FirebaseVisionImageMetadata) with a NV21
formatted image from Camera
(deprecated).
fromByteBuffer(java.nio.ByteBuffer, FirebaseVisionImageMetadata) if you
need to pre-process the image. E.g. allocate a direct ByteBuffer
and write processed pixels into the ByteBuffer.
FirebaseVisionImage factory methods will work as well, but possibly slightly
slower.
To get the best detection result, we recommend the following:
FirebaseVisionBarcodeDetectorOptions.Task
that asynchronously returns a List of detected
FirebaseVisionBarcodes. An empty list is returned by the Task
if nothing is found.