A.Cano
A.Cano

Reputation: 1

Android Vision API: read all barcodes, including duplicated

We are using this code to read all the barcodes of a file that contains 25 barcodes. It returns 23 of them because two of the barcodes are duplicated. We understand that this solution erases duplications. Is there any solution to avoid the erasure of duplicated values? We need to read all of them, even duplications.

Bitmap myBitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(),
  R.drawable.asuscode);

Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Barcode> barcodes = barcodeDetector.detect(frame);

Upvotes: 0

Views: 550

Answers (2)

pchx
pchx

Reputation: 11

Unfortunately, the API only returns a single Barcode result per unique value. This is because the barcode value is used to calculate the SparseArray index when constructing the return value.

What kind of use case do you have for wanting the duplicated result?

Upvotes: 1

sumandas
sumandas

Reputation: 565

It seems direct assignment to SparesdArray would lead to collision to remove duplicated values.

Try the below code:

SparsedArray<BarCode> myBarcode = new SparsedArray<Barcode>();
int i = 0;

for (Barcode barcode : barcodeDetector.detect(frame)) {
    myBarCode.put(i, barcode);
    i++;
}

Hope this helps.

Upvotes: 0

Related Questions