Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 22, 2020 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/d99a6827922cad89b1a5e299f28bb5cb to your computer and use it in GitHub Desktop.
Save parzibyte/d99a6827922cad89b1a5e299f28bb5cb to your computer and use it in GitHub Desktop.
document.addEventListener("DOMContentLoaded", () => {
const $resultados = document.querySelector("#resultado");
Quagga.init({
inputStream: {
constraints: {
width: 1920,
height: 1080,
},
name: "Live",
type: "LiveStream",
target: document.querySelector('#contenedor'), // Pasar el elemento del DOM
},
decoder: {
readers: ["ean_reader"]
}
}, function (err) {
if (err) {
console.log(err);
return
}
console.log("Iniciado correctamente");
Quagga.start();
});
Quagga.onDetected((data) => {
$resultados.textContent = data.codeResult.code;
// Imprimimos todo el data para que puedas depurar
console.log(data);
});
Quagga.onProcessed(function (result) {
var drawingCtx = Quagga.canvas.ctx.overlay,
drawingCanvas = Quagga.canvas.dom.overlay;
if (result) {
if (result.boxes) {
drawingCtx.clearRect(0, 0, parseInt(drawingCanvas.getAttribute("width")), parseInt(drawingCanvas.getAttribute("height")));
result.boxes.filter(function (box) {
return box !== result.box;
}).forEach(function (box) {
Quagga.ImageDebug.drawPath(box, { x: 0, y: 1 }, drawingCtx, { color: "green", lineWidth: 2 });
});
}
if (result.box) {
Quagga.ImageDebug.drawPath(result.box, { x: 0, y: 1 }, drawingCtx, { color: "#00F", lineWidth: 2 });
}
if (result.codeResult && result.codeResult.code) {
Quagga.ImageDebug.drawPath(result.line, { x: 'x', y: 'y' }, drawingCtx, { color: 'red', lineWidth: 3 });
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment