Quagga doesn't locate or decode barcodes

Viewed 5064

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>

1 Answers

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.

Related