jsQR icon indicating copy to clipboard operation
jsQR copied to clipboard

Hello, may I ask if the QR code with lighter color can not be recognized? (请问是不能识别颜色较浅的二维码吗?)

Open fivefog opened this issue 2 years ago • 3 comments

浅色+ 黄码 红码

The first two light-colored codes cannot be recognized. Is there a solution? (前两个颜色浅的码识别不了,有办法解决吗?)

fivefog avatar Aug 09 '22 10:08 fivefog

With ZBar.wasm(https://github.com/undecaf/zbar-wasm, https://github.com/samsam2310/zbar.wasm), I create an online live sample which outperforming jsQR with ability to detect multiple codes in one frame supporting multiple code types: https://output.jsbin.com/nidonin

Open the link above and point to your colorful QR codes :-)

Here is also a sample based on jsQR for comparision: https://output.jsbin.com/zevavin

fengdh avatar Aug 24 '22 04:08 fengdh

You can apply darken filter to your original image data, try both orginal and altered one with jsQR.

fengdh avatar Aug 24 '22 05:08 fengdh

We can even make it pure black and white by using the following calculations:

black = 0 - 382 white = 383 - 765

I used follows code, these qr code can be decode.

for (i = 0; i < imgData.data.length; i += 4) {
    let count = imgData.data[i] + imgData.data[i + 1] + imgData.data[i + 2];
    let colour = 0;
    if (count > 383) colour = 255;

    imgData.data[i] = colour;
    imgData.data[i + 1] = colour;
    imgData.data[i + 2] = colour;
    imgData.data[i + 3] = 255;
}

Thanks.

ReginaLiang avatar May 26 '23 05:05 ReginaLiang