serratus / quaggaJS

An advanced barcode-scanner written in JavaScript
https://serratus.github.io/quaggaJS/
MIT License
5.07k stars 979 forks source link

Quagga unable to read code generated from pdf to image #506

Open redochka opened 3 months ago

redochka commented 3 months ago

I am extracting a barcode from a pdf using FPDF than converting it to an image using pdf.js

The barcode is readable by other bar code scanner tools. however quaggajs is not able to detect it.

I am using the basic nodejs example which works with other barcodes.

What could be wrong with a barcode found in a pdf and converted to an image? output0 output_page-0001

ericblade commented 2 months ago

Hi there! Usually, the problem that I see is that there's zero whitespace around the image, which causes it to not understand where the barcode is. That doesn't appear to be the case here, but it is quite a large barcode, so I'm guessing resolutions may not be configured to handle this.

Can you provide your quagga configuration block? Also, which of these two images are we talking about? both?

redochka commented 2 months ago

Hey, yes problem happening with both images. The large image with lot of blank is just an experiment to see if it would help. My quagga config is basic:

Quagga.decodeSingle({
  // src         : "pwlo858qvoc2cgy6aqijt9ctmiszwqreypqlw7xu_page-0001.jpg",
  src         : "output0.png",
  numOfWorkers: 0,  // Needs to be 0 when used within node
  // inputStream : {
  //   size: 2000  // restrict input-size to be 800px in width (long-side)
  // },
  decoder     : {
    readers: [
      "code_128_reader",
      "ean_reader",
      "ean_8_reader",
      "code_39_reader",
      "code_39_vin_reader",
      "codabar_reader",
      "upc_reader",
      "upc_e_reader",
      "i2of5_reader",
      "2of5_reader",
      "code_93_reader",
    ], // List of active readers
    locate: true,
    debug: {
      drawBoundingBox: false,
      showFrequency: false,
      drawScanline: false,
      showPattern: false
    }

  },
}, function (result) {
  console.log("result", result);

  if (result && result.codeResult) {
    console.log("result.codeResult", result.codeResult);
    console.log("result", result.codeResult.code);
  } else {
    console.log("not detected");
  }
})