serratus / quaggaJS

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

My image is not detected #336

Open YeisonVelez11 opened 6 years ago

YeisonVelez11 commented 6 years ago

Hi friends, I congratulate you on this amazing plugin. In my case it does not work with any of the 2 images I have. What can I do to detect them?

` var Quagga = require('quagga').default;

    Quagga.decodeSingle({
        src: "20181010_084927.jpg",
        numOfWorkers: 0,  // Needs to be 0 when used within node

        decoder: {
            readers: ["code_128_reader"] // List of active readers
        },
    }, function(result) {
        console.log(result)
        if(result.codeResult) {
            console.log("result", result.codeResult.code);
        } else {
            console.log("not detected");
        }
    });

`

baaaaar code128

hcrufio88 commented 4 years ago

have you ever fix this problem?

ericblade commented 4 years ago

I can say without a doubt that the second one in this sample is due to lack of whitespace -- adding a 25px whitespace around it should fix it.

That said, I'm not good enough to be able to determine what format a barcode is in by just looking at it, but it's my assumption that the first one is either failing due to the same reason -- needs more whitespace, or failing because it's not code128 format.

@hcrufio88 probably could use more information about your configuration and samples to determine what's failing for you

hcrufio88 commented 4 years ago

Thanks I really appreciate your work. I fix the previous issue and the function works fine. Now I have another problem. WHY this code ends always with the same code?!? if I scan only a code it works, but in a for or forEach loop it gives me always one code for all.

const Quagga = require('quagga').default;

const idPratiche = [];

const filedir = [
  './temp/crop-0.jpg',
  './temp/crop-1.jpg',
  './temp/crop-2.jpg',
  './temp/crop-3.jpg'
]

filedir.forEach(function(file){
  Quagga.decodeSingle({
      src: file,
      numOfWorkers: 0,
      locate:true,
      locator:{patchSize:"large",halfSample:true},  // Needs to be 0 when used within node
      inputStream: {
          size: 800  // restrict input-size to be 800px in width (long-side)
      },
      decoder: {
          readers: ["ean_reader"] // List of active readers
      },
  }, function(result) {
   if(result.codeResult) {
  console.log(result.codeResult.code);
        let res = +(result.codeResult.code.substring(6, 12));
        let id = {fileName:file,id:res}
          idPratiche.push(id);
          console.log(idPratiche);
      } else {
        let id = {fileName:file,id:"not detected"}
          idPratiche.push(id);
      }
  });
});
Schermata 2020-04-20 alle 14 18 22
ericblade commented 4 years ago

Decoding in parallel does not work here. I am trying to fix that here https://github.com/ericblade/quagga2/pull/171

I could definitely use some additional eyes and tests on how well that works, if it works correctly.

hcrufio88 commented 4 years ago

I try to use quagga 2 but I can't make it work.

const Quagga = require('@ericblade/quagga2').default;

let path= "./crop-0.jpg"

Quagga.decodeSingle({
    src: path,
    numOfWorkers: 0,
    locate:true,
    locator:{patchSize:"large",halfSample:true},  // Needs to be 0 when used within node
    inputStream: {
        size: 800  // restrict input-size to be 800px in width (long-side)
    },
    decoder: {
        readers: ["ean_reader"] // List of active readers
    },
}, function(result) {
    if(result.codeResult) {
      var res = +(result.codeResult.code.substring(6, 12));
      var id = {fileName:path,id:res}
        console.log(id);
    } else {
        console.log("not detected");
    }
});

the result of that in node 12.16.1 is:

Schermata 2020-04-21 alle 20 54 00

I only install the nom package with

npm install --save @ericblade/quagga2
ericblade commented 4 years ago

it seems i have somehow 'fixed' it so that it should be just require('@ericblade/quagga2') rather than require(...).default .. that wasn't intentional, but i'm not sure what change did it, right off..

ericblade commented 4 years ago

you'd also have to use a custom built one with that pull request, until i'm comfortable releasing that patch, which might take a little while, because it makes a lot of internal changes that need to be run out in real use for a while i think

hcrufio88 commented 4 years ago
  1. in the previous post i just wanted to try quagga2 from npm and it don't work with the .default require, now I try another time without .default and it worked! I suggest to change the readme on npmjs because it says to use the .default require and it's wrong.
  2. I builded the dev branch and try to do the parallel decode and it worked!! thanks man really nice work with that!!