6

I'm trying to make a barcode scanner with Quagga. But I can only see the live version of the webcam, but it doesn't recognize any (code 128) barcode. (The snippet doesn't show the webcam on stackoverflow.)

I think that I'm missing a step, but hope someone here can push me in the right direction.

Quagga.init({
  inputStream : {
    name : "Live",
    type : "LiveStream",
    target: document.querySelector('#scanblock')
  },
  decoder : {
    readers : ["code_128_reader"]
  }
   }, function(err) {
    if (err) {
     console.log(err);
     return
    }
    console.log("Initialization finished. Ready to start");
    Quagga.start();
   });
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://serratus.github.io/quaggaJS/examples/js/quagga.min.js" type="text/javascript"></script>
  </head>
  <body>
    <header style="text-align: center; margin-top:3%;">
      <h3>Barcode Scanner</h3>
      <hr/>
    </header>
    <div style="text-align: center; margin-top: 6%;">
      <div id="scanblock"></div>
    </div>
  </body>
</html>
mx0
  • 6,445
  • 12
  • 49
  • 54
D. J.
  • 684
  • 6
  • 25
  • I did a fairly large barcode implementation and used both QuaggaJS and ZXing. Have you tried the other possible barcode values (ean_reader, upc_reader, etc.) to ensure that it's not just an issue with the code_128 you're trying to scan? If that's not it, is it actually outlining the barcode on the screen? – maxshuty Jun 02 '17 at 12:47
  • Thanks for your reply, other barcodes won't work aswell. And no, it does'nt outline the barcode. It does only show the live webcam. – D. J. Jun 02 '17 at 12:53
  • Are there any errors in your console? – maxshuty Jun 02 '17 at 13:25
  • Nope, the only thing displayed in the console is the "Initialization finished. Ready to start". I think that I'm missing a part of the code, but not sure about what part. – D. J. Jun 02 '17 at 13:26
  • 1
    you need to implement Quagga.onProcessed and Quagga.onDetected – Jymbo Jan 21 '18 at 11:05

1 Answers1

0

Jymbo is correct. You must also implement .onProcessed() and .onDetected(). I recommend executing.stop() when onDetected returns a result. Otherwise it will continue to process and detect -- forever.

In case you hadn't figured it out, it only detects instances of the reader defined on decoder.

doug5solas
  • 77
  • 10