Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't detect this QR code #516

Closed
Gazentia opened this issue Mar 25, 2022 · 2 comments
Closed

Can't detect this QR code #516

Gazentia opened this issue Mar 25, 2022 · 2 comments

Comments

@Gazentia
Copy link

Gazentia commented Mar 25, 2022

image

  const formats = [BarcodeFormat.QR_CODE]
  hints.set(DecodeHintType.POSSIBLE_FORMATS, formats)
  ...
  const codeReader = new BrowserMultiFormatReader(hints, 500)
@Gazentia Gazentia changed the title Can't scan this QR code Can't detect this QR code Mar 25, 2022
@sacru2red
Copy link

same issue.
there are many same issue..

On using same Image case

@zxing/browser works but @zxing/library not work

it's create-react-app test code

import React from 'react';
import { BrowserQRCodeReader } from '@zxing/browser';
import qr from './qr.png'

function App() {

  React.useEffect(() => {
    const codeReader = new BrowserQRCodeReader();
        const img = document.getElementById('qr');
        codeReader
            .decodeFromImageElement(img)
            .then(result => console.log(result.text))
            .catch(err => console.error(err));
  }, [])

  return (
    <div className="App">
      <img
        alt="qr"
        id="qr"
        src={qr}
      />
    </div>
  );
}

export default App;

and here's node code

const Zxing = require('@zxing/library');
const fs = require('fs')

const qRCodeReader = new Zxing.QRCodeReader()
console.log('qRCodeReader', qRCodeReader)
const hints = new Map();
const formats = [Zxing.BarcodeFormat.QR_CODE, Zxing.BarcodeFormat.DATA_MATRIX];
hints.set(Zxing.DecodeHintType.POSSIBLE_FORMATS, formats);

fs.readFile('./qr.png', (err, imgBuffer) => {
    if (err) throw err
    console.log('imgBuffer', imgBuffer)
    var sizeOf = require('image-size');
    sizeOf('./qr.png', (err, dimensions) => {
        if (err) throw err
        console.log(dimensions.width, dimensions.height);
        const { width: imgWidth, height: imgHeight } = dimensions
        const imgByteArray = new Uint8ClampedArray(imgBuffer)
        console.log('imgByteArray', imgByteArray)
        const luminanceSource = new Zxing.RGBLuminanceSource(imgByteArray, imgWidth, imgHeight);
        const binaryBitmap = new Zxing.BinaryBitmap(new Zxing.HybridBinarizer(luminanceSource));
        const result = qRCodeReader.decode(binaryBitmap, hints).getText()
        console.log(result)
    });
})

and my qrcode
qr

Copy link

Stale issue message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants