FirebaseVisionBarcodeDetector

public class FirebaseVisionBarcodeDetector extends Object
implements Closeable Closeable

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());
 

 
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(...);
 

Public Method Summary

void
close()
Closes this FirebaseVisionBarcodeDetector and releases its model.
Task<List<FirebaseVisionBarcode>>
detectInImage(FirebaseVisionImage image)
Detects barcodes from the supplied image.

Inherited Method Summary

Object
clone()
boolean
equals(Object arg0)
void
finalize()
final Class<?>
getClass()
int
hashCode()
final void
notify()
final void
notifyAll()
String
toString()
final void
wait(long arg0, int arg1)
final void
wait(long arg0)
final void
wait()
abstract void
close()
abstract void
close()

Public Methods

public void close ()

Closes this FirebaseVisionBarcodeDetector and releases its model.

Throws

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:

All other FirebaseVisionImage factory methods will work as well, but possibly slightly slower.

To get the best detection result, we recommend the following:

Returns

ML Kit for Firebase provided ready-to-use ML solutions for app developers. New apps should use the standalone ML Kit library for on-device ML and Firebase ML for cloud-based ML.

Updated Feb 20, 2025