quagga2 icon indicating copy to clipboard operation
quagga2 copied to clipboard

scan image fail

Open leosteven2018 opened this issue 2 years ago • 5 comments

Hi, I have research quagga for a few day, I try to use JsBarcode to create the barcode and use Quagga to scan it in image type and liveStream type. But sometime I cannot scan and find out the result code in image type. For example, I created the barcode with the string "1234", I can get the code when I use liveStream, but fail with the base64 url maked from canvas.toDataURL(), also the downloaded image. I tried many code, "12345678", "201108040076", "201243219876", only some of those success. In fact, when I change the fontsize/text margin/margin of the barcode, the accuracy rate could be imporved but it is still affected by many things such as space. Would you like to tell me what are the reasons affect the accuracy rate or how to improve it?

Thanks!

leosteven2018 avatar Apr 21 '23 03:04 leosteven2018

Thank you for filing an issue! Please be patient. :-)

github-actions[bot] avatar Apr 21 '23 03:04 github-actions[bot]

If you're using locate: true (i believe that's the default) and not setting an area to scan in specifically, the biggest problem I've run into while scanning retail barcodes is the amount of space around the barcode. If there's other images or text, or other barcodes very close to the barcode trying to be located, location will often fail.

It would be helpful to get some of the images and their corresponding dataURL if possible, since it seems like one is failing?

ericblade avatar Apr 21 '23 05:04 ericblade

I used Quagga.decodeSingle() to scan the image file. Here is the code follow as:

// Function to create the BarCode
createCode() {
    JsBarcode("#barcode", this.inputValue, {
        format: "CODE128",
        fontSize: 40,
        // textMargin: 25,
        // margin: 50
    });
},

// Function to scan the BarCode
scanCode() {
    let target = document.getElementById('barcode');
    let url = target.toDataURL();
    Quagga.decodeSingle({
        decoder: {
            readers: ["code_128_reader"]
        },
        locate: true,
        src: url  // base64 png
        // src: './download.png' // download via <a></a>
    }, (res) => {
        if (!res) {
            return false;
        }
        if (res.codeResult) {
            console.log(res.codeResult)
        } else {
            console.log('Recognize fail')
        }
    })
}

download code2 code2 code3

Those images is clear to be scanned, but I just only scan successful for the second and the fourth images, did I have something miss in the configuration?

By the way, I used margin: 50 in createCode() and download two images: 0421_1 0421_2 one is "1526 8594", and it is successful, the other one "15268594" is fail. How can I control it?

leosteven2018 avatar Apr 21 '23 06:04 leosteven2018

I don't know how long it'll take me to pull these and check them out, but my guess is that having a larger margin on top and bottom from any other things would help. If these labels are printed along with any other text/images/something

Of course, image based scanning is inherently less reliable than laser scanning, and I've never made any claims that Quagga is problem free :-D BUT most of the problems that people have reported were usually able to be handled with some adjustments to settings or images...

anyway, i'll get back to you when i can :) if you find any further info, please add it

ericblade avatar Apr 21 '23 09:04 ericblade

Thanks! As you say, laser scanning is more reliable when I use the external camera, I can scan those images with the suitable angle successful even thought they fail in decodeSingle().

leosteven2018 avatar Apr 21 '23 10:04 leosteven2018