quaggaJS icon indicating copy to clipboard operation
quaggaJS copied to clipboard

No results from the scanner on > iOS 14

Open malte94 opened this issue 2 years ago • 16 comments

The scanning functionality of Quagga stopped working. I tried different aspectRatios and different configurations regarding the camera selection without any success.

The camera selection, on the other hand, and general implementation work fine – the stream starts without any issues. No barcodes (ean_code) are recognized though.

Android works without any issues.

 const QuaggaInit = () => {
        Quagga.init(
            {
                inputStream: {
                    type: "LiveStream",
                    constraints: {
                        width: {
                            min: 450
                        },
                        height: {
                            min: 300
                        },
                        deviceId: selectedDevice ? selectedDevice : "default",
                        facingMode: "environment",
                        /*aspectRatio: {
                            "min": 1,
                            "max": 2
                        }*/
                    }
                },
                locator: {
                    "patchSize": "medium",
                    "halfSample": true
                },
                numOfWorkers: 2,
                frequency: 10,
                decoder: {
                    readers: [
                        "ean_reader",
                    ]
                },
                locate: true
            }, err => {
                if (err) {
                    console.log(err, "error msg");
                }
                Quagga.start();
                return () => {
                    Quagga.stop()
                }
            });
    }

    React.useEffect(() => {
        getDevices();
        checkPermissions();
        Quagga.onProcessed(result => {
            var drawingCtx = Quagga.canvas.ctx.overlay,
                drawingCanvas = Quagga.canvas.dom.overlay;

            if (result) {
                if (result.boxes) {
                    drawingCtx.clearRect(
                        0,
                        0,
                        Number(drawingCanvas.getAttribute("width")),
                        Number(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(detected);

    }, []);

    const detected = result => {
        onDetected(result.codeResult.code);
    };

Test device: iPhone 12 Pro

malte94 avatar Jul 13 '22 08:07 malte94

I'm told that selecting an aspectRatio: { ideal: 1 } in your constraint works there, although I can't confirm that since I lack any iOS devices.

ericblade avatar Jul 15 '22 07:07 ericblade

Thank you @ericblade Unfortunately, that won't fix the issue (anymore).

malte94 avatar Jul 15 '22 09:07 malte94

just realized it's aspectRatio: { ideal: 1 } ..

might take a look through this thread for some ideas https://github.com/ericblade/quagga2/issues/419

ericblade avatar Jul 15 '22 15:07 ericblade

@ericblade

Thank you. I tried this configuration. Still not working properly.

The iPhone camera appears to be incredibly picky. I scanned one EAN code succesfully, which had nearly the exact camera format. As soon as some text is around the EAN, or the EAN is quite small and can not be recorded in the camera's format due to exceeding the minimum focus distance of the iPhone's camera, the scanner always fails.

On the other hand, Android scans EANs without any problems, even if they are not in the camera format, surrounded by text or very small.

So would you suppose that this is an issue related to the library (The iPhone camera itself works perfectly, focusses correctly) or due to Safari/iOS?

malte94 avatar Jul 22 '22 08:07 malte94

I wish I had any more insight to that. The control that a web app has, and more so on iOS, compared to a native app, over the camera functionality is pretty minimal. It could be hardware, it could be OS/Browser, or it c ould be the library. Could be a combination of all of that just not working together in expected ways that work elsewhere. :|

ericblade avatar Jul 22 '22 23:07 ericblade

does you fixed it? i have same issues, this beacause onProcessed() function run only one time when init. So it never get onDetected()

JonSnow-vn avatar Aug 16 '22 08:08 JonSnow-vn

@JonSnow-vn Nope, but Android works fine. onDetected() is called correctly each time on detection :)

malte94 avatar Aug 16 '22 09:08 malte94

@JonSnow-vn Nope, but Android works fine. onDetected() is called correctly each time on detection :)

yes, me too, this problem only on iphone. Like what i say, on iphone, onProcessed() function run only one time when init. I test on macbook pro and ipad pro its work fine. I don't konw ipad mini is work? i dont have this.

JonSnow-vn avatar Aug 16 '22 09:08 JonSnow-vn

Interesting observation, I have not debugged it that in-depth.

malte94 avatar Aug 16 '22 09:08 malte94

I wish I had any more insight to that. The control that a web app has, and more so on iOS, compared to a native app, over the camera functionality is pretty minimal. It could be hardware, it could be OS/Browser, or it c ould be the library. Could be a combination of all of that just not working together in expected ways that work elsewhere. :|

you have any idea?

JonSnow-vn avatar Aug 18 '22 04:08 JonSnow-vn

Unfortunately, I don't. The one person using my app on iOS isn't reporting any problems.

ericblade avatar Aug 18 '22 08:08 ericblade

Unfortunately, I don't. The one person using my app on iOS isn't reporting any problems.

I can confirm, is working fine here.

fabricyo avatar Sep 29 '22 23:09 fabricyo

Anyone have any other ideas to resolve this? I'm still unable to scan on my iPhone 13 mini after messing around with setting aspectRatio.

erikmillergalow avatar Oct 27 '22 01:10 erikmillergalow

Is this issue resolved?

PriyaN-d avatar Aug 01 '24 11:08 PriyaN-d

@PriyaN-d Yes, we were able to get this working again last year - though we did have to add a way for users to try out each available camera themselves (different models expose different settings/lenses, front/back/wide angle etc...)

erikmillergalow avatar Aug 01 '24 17:08 erikmillergalow