zbar icon indicating copy to clipboard operation
zbar copied to clipboard

Extend zbar to recognize QR codes created by swish.nu?

Open petterreinholdtsen opened this issue 2 years ago • 5 comments

I just visited https://www.swish.nu/skapa-qr-kod and created the attached QR code. When I asked zbarimg to give me the QR code content, I got this message instead:

scanned 0 barcode symbols from 1 images in 0.21 seconds


WARNING: barcode data was not detected in some image(s)
Things to check:
  - is the barcode type supported? Currently supported symbologies are:
        . EAN/UPC (EAN-13, EAN-8, EAN-2, EAN-5, UPC-A, UPC-E, ISBN-10, ISBN-13)
        . DataBar, DataBar Expanded
        . Code 128
        . Code 93
        . Code 39
        . Codabar
        . Interleaved 2 of 5
        . QR code
        . SQ code
  - is the barcode large enough in the image?
  - is the barcode mostly in focus?
  - is there sufficient contrast/illumination?
  - If the symbol is split in several barcodes, are they combined in one image?
  - Did you enable the barcode type?
    some EAN/UPC codes are disabled by default. To enable all, use:
    $ zbarimg -S*.enable <files>
    Please also notice that some variants take precedence over others.
    Due to that, if you want, for example, ISBN-10, you should do:
    $ zbarimg -Sisbn10.enable <files>

Can zbarimg be improved to recognize this QR code? This was using zbar 0.23.90-1 in Debian Bullseye.

qr-swish

petterreinholdtsen avatar Oct 05 '21 07:10 petterreinholdtsen

Hej @petterreinholdtsen! My OSS project named Koder which is based on zbar 0.23.90 (compiled into WebAssembly) is able to decode this QR. Check out the demo here: https://qr.maslick.tech

maslick avatar Jan 30 '22 10:01 maslick

IMG_0385 IMG_0384

maslick avatar Jan 30 '22 10:01 maslick

Can it also decode it if you give it the image directly, instead of pointing a camera at the image?

petterreinholdtsen avatar Feb 02 '22 07:02 petterreinholdtsen

For this you need to find the best spot (angle, focus, distance, etc.), which is easier to do live, and not by feeding the algorithm just 1 image, even in great resolution.

Here's a photo sample of your QR code I was able to recognize with Koder:

sample-photo

You can use this snippet and experiment with a number of samples (focus, distance, image quality, resolution):

$ npm i @maslick/koder
$ touch test.js
$ node test.js
const Koder = require('@maslick/koder');
const {loadImage, createCanvas} = require("canvas");

const getImageData = async (src) => {
  const img = await loadImage(src);
  const canvas = createCanvas(img.width, img.height);
  const ctx = canvas.getContext('2d');
  ctx.drawImage(img, 0, 0);
  return {
    data: ctx.getImageData(0, 0, img.width, img.height).data,
    width: img.width,
    height: img.height
  };
};

(async () => {
  const url = 'https://user-images.githubusercontent.com/5644706/152113630-a41fcbdc-3860-4e74-bf39-038bbe37594c.png';
  const koder = await new Koder().initialized;
  const {data, width, height} = await getImageData(url);

  const t0 = new Date().getTime();
  const res = koder.decode(data, width, height);
  const t1 = new Date().getTime();

  console.log(`Scanned in ${t1-t0} ms`);      // Scanned in 9 ms
  console.log(res);                           // C+4722222222;50;Test+av+QR-kode+Swish;0
})();

maslick avatar Feb 02 '22 07:02 maslick

[Pavel Maslov]

For this you need to find the best spot (angle, focus, distance, etc.), which is easier to do live, and not by feeding the algorithm just 1 image, even in great resolution. You can use this script and experiment with a number of samples (focus, distance, image quality):

I was just curious how your program work with one image in perfect focus, as it is the setup I am interested in, ie running QR code detection on prescanned images.

-- Happy hacking Petter Reinholdtsen

petterreinholdtsen avatar Feb 02 '22 07:02 petterreinholdtsen