cozmo / jsQR

A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
https://cozmo.github.io/jsQR/
Apache License 2.0
3.63k stars 600 forks source link

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

Open fivefog opened 1 year ago

fivefog commented 1 year ago

浅色+ 黄码 红码

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

fengdh commented 1 year ago

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 commented 1 year ago

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

ReginaLiang commented 1 year ago

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.