This class is deprecated.
The standalone ML Kit SDK replaces this API. For more information, refer to the migration guide.
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());
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);
FirebaseVisionImage
.
Task
<List<FirebaseVisionBarcode>> task = barcodeDetector.detectInImage(image);
task.addOnSuccessListener(...).addOnFailureListener(...);
Public Method Summary
void |
close()
Closes this
FirebaseVisionBarcodeDetector and releases its model.
|
Task<List<FirebaseVisionBarcode>> |
Inherited Method Summary
Public Methods
public void close ()
Closes this
FirebaseVisionBarcodeDetector
and releases its model.
Throws
IOException |
---|
public Task<List<FirebaseVisionBarcode>> detectInImage (FirebaseVisionImage image)
Detects barcodes from the supplied image.
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(java.nio.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.
To get the best detection result, we recommend the following:
- The image size is at least 1280 x 960.
- The barcode covers most of the image.
- Narrow down the barcode formats in
FirebaseVisionBarcodeDetectorOptions
.
Returns
- A
Task
that asynchronously returns aList
of detectedFirebaseVisionBarcode
s. An empty list is returned by theTask
if nothing is found.