Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom constraints not applied in Quagga.init #533

Open
myleftshoe opened this issue Feb 19, 2024 · 3 comments
Open

Zoom constraints not applied in Quagga.init #533

myleftshoe opened this issue Feb 19, 2024 · 3 comments

Comments

@myleftshoe
Copy link

myleftshoe commented Feb 19, 2024

Zoom only works when the constraint is applied to the active track after calling Quagga.init. I.e. this code works:

        Quagga.init(
            {
                inputStream: {
                    name: 'Live',
                    type: 'LiveStream',
                    target: video,
                    constraints: {
                        width: window.innerWidth,
                        height: 480,
                        facingMode: 'environment',
                    },
                    // area: {
                    //     // defines rectangle of the detection/localization area. Works with or without locator enabled
                    //     top: "40%",
                    //     right: "10%",
                    //     left: "10%",
                    //     bottom: "40%",
                    // },
                },
                locate: true,
                locator: {
                    halfSample: true,
                    patchSize: 'x-large',
                    willReadFrequently: true,
                },
                decoder: {
                    readers: ['code_128_reader'],
                },
            },
            function (err) {
                if (err) {
                    console.warn(err)
                    return
                }
                const track = Quagga.CameraAccess.getActiveTrack()
                track.applyConstraints({
                    advanced: [{ zoom: 2 }],
                })
                Quagga.start()
                Quagga.onDetected(handleScan)
            },
        )

But this code does not:

        Quagga.init(
            {
                inputStream: {
                    name: 'Live',
                    type: 'LiveStream',
                    target: video,
                    constraints: {
                        width: window.innerWidth,
                        height: 480,
                        facingMode: 'environment',
                        advanced: [{ zoom: 2 }],
                    },
                    // area: {
                    //     // defines rectangle of the detection/localization area. Works with or without locator enabled
                    //     top: "40%",
                    //     right: "10%",
                    //     left: "10%",
                    //     bottom: "40%",
                    // },
                },
                locate: true,
                locator: {
                    halfSample: true,
                    patchSize: 'x-large',
                    willReadFrequently: true,
                },
                decoder: {
                    readers: ['code_128_reader'],
                },
            },

I also tried using zoom: 2 directly, i.e. without advanced

This is a cosmetic issue really because you can see the zoom jump from the initial to zoom:2 rather than already zoomed on start.
(Other than that I am getting really quick and accurate detection results, much appreciation!)

Copy link

Thank you for filing an issue! Please be patient. :-)

@ericblade
Copy link
Owner

That's great that it works well! Thanks for the tip. I'd have to do a little research on it, probably try it out with a barebones test not using quagga at all, but I can think of two possible reasons.. either a) it doesn't pass the zoom parameter into the api, or b) the api is ignoring the zoom parameter until after the camera has been initialized. a should be easily fixable (i think :) ) b would probably mean it's more of a browser problem that I wouldn't really be able to do anything about....

I think the last time I looked at the zoom api, it wasn't implemented anywhere yet.. so.. good to take another look. If it's well supported, could add some functionality to the CameraAccess to manipulate it, too

@myleftshoe
Copy link
Author

FYI I'm using it in a standalone Safari webapp on iPhone 11. It only works when specified using the advanced array. And to confuse things more, getSettings returns an object with { zoom: 1 }, not { zoom: 2 } nor advanced: [{ zoom: 2 }]. My point is that it is zoomed even though the settings indicate that it is not. Incidentally, getCapabilities returns zoom.min: 0.5 and zoom.max: 2.

The zoom really does make a massive difference - I don't get any detections without it, and I fiddled around a lot trying to make it work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants