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.7k stars 607 forks source link

Load binarized unavailable for folks #92

Closed Johann-S closed 5 years ago

Johann-S commented 6 years ago

Hi,

First of all thank you for your awesome project 👍

I work on a personal project where I can decode QR Code from an URL or from an input file, but when I see your unit test you use a personal method loadBinarized based on your code source, but without that method I cannot decode my QR Codes

Example where you use loadBinarized: https://github.com/cozmo/jsQR/blob/master/src/decoder/test.ts#L8

See my file where I try to decode QR Codes: https://github.com/Johann-S/AwesomeQR-Desktop/blob/master/src/util.js

cozmo commented 6 years ago

Hey @Johann-S sorry I don't think I understand the issue. jsQR takes in raw image data, not binarized images. As such any consumers shouldn't need to interact with binarized images. The binarized form of images are an internal construct of jsQR that callers should not need to know about or use.

Can you clarify why you need loadBinarized?

Johann-S commented 6 years ago

Because currently I'm not able to detect any QR Codes with jsQR, my code looks like yours : https://github.com/cozmo/jsQR/blob/master/tests/helpers.ts#L21

And with this code I'm unable to read any QR Codes and I saw you use loadBinarize in some other tests which pass successfully.

I test using some of your QR Codes in your tests folder

cozmo commented 5 years ago

loadBinarize is an internal helper for our test cases, to test (internal) methods that accept binarized images. The API of jsQR does not expose/require binarized images, rather it just accepts image data, as documented here.

In practice this would look something like this (for pngs)

import jsQR from "jsqr";
import * as fs from "fs";
import * as png from "upng-js";

const imageData = png.decode(fs.readFileSync("./path/to/png/file.png"))
const code = jsQR(png.toRGBA8(imageData), imageData.width, imageData.height);
if (code) {
  console.log(code);
}

I'm going to close this issue, since not exposing loadBinarized/methods that require binarized images is a purposeful design decision and shouldn't impact your usage of the library, but feel free to comment etc if you have any additional questions about this.