serratus/quaggaJS

Modern phones have multiple environment facing cameras.. Quagga picks wrong one

Closed this issue · 8 comments

Need ability to specify which camera to use beyond 'environment' and 'user'

Query the devices using Quagga.CameraAccess.enumerateVideoDevices i believe the function is called, and then you can specify a deviceId instead of a 'environment' or 'user'.

I guarantee that that is not a problem with the library itself, as I use this function every day -- can you post your Quagga.init() configuration? Also might help to say what kind of device, though I'm not really in depth familiar with anything other than the 2 that I've used Q with routinely, a N5 and a G6...

On my G6, there are two rear cameras and a front, one of the rears is wide-angle, and can't read anything barcode like at all, and that's the default 'environment' camera, so i definitely use the deviceId constraint exclusively.

I have tested it again, and each option pulls up the front facing camera! only 'environment' chooses a rear.
I'm using a Huawei P30 Pro.
I've tried other JS solutions as a result, and they all show a different camera for each deviceId as expected..
Here is my config:
`
{
inputStream: {
name: "Live",
type: "LiveStream",
constraints: {
height: this.height,
width: this.width,
facingMode: this.selectedCamera
},
target: document.querySelector('#interactive')
},

                decoder: {
                    readers: ["code_39_reader", "code_39_vin_reader"],
                    multiple: false
                },
                locate: true
            }

`
Sorry, I am not sure how to make JSON format nicely here..

You want to replace the 'facingMode' key with 'deviceId' i believe is the name for the key used in constraints to ask for a specific camera.

https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints

to format code in github, surround it with three backticks ( ` )

I am able to get a list of cameras and then use the correct one. But how do you display this to your users? There isn't much information about what each camera is or how to programmatically select which to use.

Please let me know if you had better luck?

Unfortunately, my experience with cell cameras is that it tends to return something like "device 0" and "device 1" for the valid camera names, if not just the hex ID of the device. It's pretty crappy. In Windows, the enumerateDevices call returns the actual names of the devices.

I use a form select element to get the user's choice (this is from a laptop PC that presently has a built-in camera, and a VCR connected to it, no external cameras)

image