serratus/quaggaJS

Code 128 Reader doesnt work

FynniX opened this issue · 1 comments

Quagga.init({
inputStream: {
name: "Live",
type: "LiveStream",
target: document.querySelector('#scanner-container'),
constraints: {
width: 480,
height: 320,
facingMode: "environment"
},
},
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"
],
debug: {
showCanvas: true,
showPatches: true,
showFoundPatches: true,
showSkeleton: true,
showLabels: true,
showPatchLabels: true,
showRemainingPatchLabels: true,
boxFromPatches: {
showTransformed: true,
showTransformedBox: true,
showBB: true
}
}
},
}, function (err) {
if (err) {
console.log(err);
return
}

        console.log("Initialization finished. Ready to start");
        Quagga.start();

        // Set flag to is
        document.getElementById("scanner-container").style.display = "block"
        _scannerIsRunning = true;
    });

    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 });
        }
    });

    Quagga.onDetected(function (result) {
        const copyText = document.getElementById("barcode");

        copyText.value = result.codeResult.code

        /* Select the text field */
        copyText.select();
        copyText.setSelectionRange(0, 99999); /* For mobile devices */

        /* Copy the text inside the text field */
        document.execCommand("copy");

        /* Alert the copied text */
        alert("Barcode wurde kopiert: " + result.codeResult.code + " Format: " + result.codeResult.format);
    });

The code_128_reader doesnt work. I tested it with a barcode from a https://barcode.tec-it.com/de and with real ones. Any ideas?

First, remove any readers you're not using, they could cause false results to be returned.

Second, I'd guess it's possibly related to the camera device. High quality cameras that autofocus and are not wide-angle are most desireable. Unfortunately, there doesn't seem to be a way to control autofocus via getUserMedia() presently, nor any obvious way to detect wide-angle vs non. I've resorted to allowing the user to select which camera device is best and storing that selection, then using the deviceId constraint to select that every time.

What sort of hardware are you trying to use it with?