library icon indicating copy to clipboard operation
library copied to clipboard

Can't detect this QR code

Open Gazentia opened this issue 2 years ago • 2 comments

image

  const formats = [BarcodeFormat.QR_CODE]
  hints.set(DecodeHintType.POSSIBLE_FORMATS, formats)
  ...
  const codeReader = new BrowserMultiFormatReader(hints, 500)

Gazentia avatar Mar 25 '22 07:03 Gazentia

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

sacru2red avatar Apr 07 '22 10:04 sacru2red

Stale issue message

github-actions[bot] avatar Apr 29 '24 10:04 github-actions[bot]