Code Monkey home page Code Monkey logo

Comments (8)

undecaf avatar undecaf commented on June 9, 2024 1

IMHO this cannot be a bug of zbar-wasm because this module does not control the camera in any way, i.e. it can neither switch beween front and back camera nor prevent this.

Edit: when writing this, I did not consider the example cited below which actually does select a camera.

from zbar-wasm.

opicron avatar opicron commented on June 9, 2024 1

Ah, I think in main.js this needs to be adressed:

navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: 'environment' } })

In here we can determine exact deviceID. I will improve and report back when it works.

from zbar-wasm.

undecaf avatar undecaf commented on June 9, 2024 1

Unfortunately, in Safari/iOS this will still only give us some camera facing the environment, not necessarily the high-resolution camera.

In recent WebKit browsers one could add the zoom capability to the MediaTrackConstraints, this should prevent fisheye cameras from being selected (only guessing, not tested).

from zbar-wasm.

opicron avatar opicron commented on June 9, 2024

By selecting the last camera in the available devices most phones return the correct enviroment camera. As such:

            // List cameras and microphones.
            navigator.mediaDevices.enumerateDevices()
                .then((devices) => {
                    devices.forEach((device) => {
                        if (device.kind == 'videoinput') {
                            deviceCam = device.deviceId;
                        }

                    });
                    constraints = {
                        audio: false,
                        video: {
                            width: {
                                min: 1280,
                                ideal: 1920,
                                max: 2560,
                            },
                            height: {
                                min: 720,
                                ideal: 1080,
                                max: 1440
                            },
                            deviceId: deviceCam
                        }
                    }
                    navigator.mediaDevices.getUserMedia(constraints)
                        .then(stream => {

                            videoContainer.srcObject = stream

                        })
                        .catch(error => {
                        })
                    detectVideo(true);
                })
                .catch((err) => {
                    console.error(`${err.name}: ${err.message}`);
                });

from zbar-wasm.

undecaf avatar undecaf commented on June 9, 2024

Thank you @opicron for your investigation!

I would not feel well, however, including this workaround in the example since I could not find any specification that guarantees that the last device represents the environmental camera.

Instead, I am thinking about replacing the line

navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: 'environment' } })

with

navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: { exact: 'environment' } } })

which requires rather than just requests a device facing the environment (specified here).

Unfortunately, I do not have an iPhone available for testing. I would appreciate very much if you could test this idea; if this works then I would like to modify the example accordingly.

from zbar-wasm.

opicron avatar opicron commented on June 9, 2024

Yes, an exact match was my first approach. But that didnt work out unfortunately. The above case works for all iphones in our company. And I see referrals to this solution being adres in multiple forums.

https://www.reddit.com/r/javascript/comments/8eg8w5/choosing_cameras_in_javascript_with_the/

from zbar-wasm.

opicron avatar opicron commented on June 9, 2024

If we add facingMode: { exact: 'environment' } to the above example code which gets the devices it might be even more consistent.

from zbar-wasm.

opicron avatar opicron commented on June 9, 2024

Going to check this too. Thanks for lead.

from zbar-wasm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.