qr-scanner icon indicating copy to clipboard operation
qr-scanner copied to clipboard

Possible with Barcodes?

Open ceh137 opened this issue 3 years ago • 8 comments
trafficstars

I would like to use this library for scanning barcodes. Is it possible to configure it that way?

ceh137 avatar Nov 01 '22 08:11 ceh137

Seems to be similar to https://github.com/nimiq/qr-scanner/issues/193 ?

arcadius avatar Feb 23 '23 16:02 arcadius

It should not be too complex to achieve

See: https://github.com/nimiq/qr-scanner/blob/abcfe1bce2703721408d8ce7ebde94a359998506/src/qr-scanner.ts#L656

arcadius avatar Feb 23 '23 17:02 arcadius

hi @arcadius , I tried your suggestion and it seems like adding more formats is not enough to get the scanner to return barcode results.

You can see my changes at my fork: https://github.com/nimiq/qr-scanner/compare/master...toddp:qr-scanner:master

I'd really like to be able to use qr-scanner for other barcode types, otherwise I'll have to switch to a different module. Can we raise this as a feature request?

toddp avatar Jun 26 '23 15:06 toddp

Scanning for multiple types of barcodes inevitably brings perfomances down. Could we make it as a prop in the options object when initializing ?

Angrigo avatar Jul 02 '23 08:07 Angrigo

Following up to my previous comment:

I managed to get other non-qr-code formats working with qr-scanner. A couple issues:

MacOS and iOS browsers do no support the BarcodeDetector API:

https://caniuse.com/mdn-api_barcodedetector

So even though I passed the additional types to BarcodeDetector in qr-scanner like this:

        return new BarcodeDetector({ formats: ['code_128','code_39','code_93','codabar','ean_13','ean_8','itf','qr_code','upc_a','upc_e'] });

It wasn't working in my browser.

I then added https://github.com/undecaf/barcode-detector-polyfill to my application, and exposed it like this:

    try {
        globalThis.BarcodeDetector.getSupportedFormats();
    } catch {
        globalThis.BarcodeDetector = barcodeDetectorPolyfill.BarcodeDetectorPolyfill;
    }

before instantiating the QrScanner .

One enhancement I'd suggest is allowing QrScanner constructor to take an optional set of formats, which it can then pass into BarcodeDetector. This might also eliminate your need to provide the backup worker.ts.

hope this helps!

toddp avatar Jul 04 '23 16:07 toddp

Let me share my experience.

Macbook, M2, Ventura 13.2.1 Chrome Version 116.0.5845.187 (Official Build) (arm64)

I cloned @toddp repo - https://github.com/toddp/qr-scanner. But the demo page still recognised only QR codes. I found next line in the src/qr-scanner.ts and removed it:

if (isChromiumOnMacWithArmVentura) return createWorker();

After the yarn build the demo page works and detects all the specified formats (code_128, ean_13 in my case).

angarsky avatar Sep 19 '23 19:09 angarsky