Javascript 如何使用WEB USB API在浏览器中从相机获取图片

Javascript 如何使用WEB USB API在浏览器中从相机获取图片,javascript,webusb,Javascript,Webusb,我正在尝试将usb网络摄像头连接到我的chrome浏览器。我可以在chrome上连接设备,也可以获取名称和配置,但是如何从网络摄像头获取图像 我正在使用下面的代码访问usb设备,但如何继续。欢迎任何链接或建议。谢谢 button.addEventListener('click', async () => { navigator.usb.requestDevice({ filters: [{ vendorId: 6403}] }) .then(device =&g

我正在尝试将usb网络摄像头连接到我的chrome浏览器。我可以在chrome上连接设备,也可以获取名称和配置,但是如何从网络摄像头获取图像

我正在使用下面的代码访问usb设备,但如何继续。欢迎任何链接或建议。谢谢

button.addEventListener('click', async () => {
  navigator.usb.requestDevice({ filters: [{ vendorId: 6403}] })
            .then(device => {
    
                console.log(device);
                const constraints = {
                    video: true,
                };
    
                device.getUserMedia(constraints) // this is not working it works only for webcams
                    .then((stream) => {
                      player.srcObject = stream;
                    })
            .catch(error => { console.log(error); });
    
            })
    
    
    
    
    
    });
我通过isochronousTransferIn()计算出,我们可以流式传输视频和音频,但仍然不起作用

button.addEventListener('click', async () => {
        navigator.usb.requestDevice({ filters: [{ vendorId: 6403 }] })
            .then(selectedDevice => {
                device = selectedDevice;
                return device.open(); // Begin a session.
            })
            .then(() => device.isochronousTransferIn(1, 64)) // Select configuration #1 for the device.
            .then((result) => console.log(result)) // Select configuration #1 for the device.
            .catch(error => { console.log(error); });




    });

你知道USB设备类是如何工作的,对吗?实现UVC的主机端并非易事,因此WebUSB可能不是从网络摄像头获取媒体的正确API,为什么不使用WebRTC或
MediaDevices
API?是的,但问题是,MediaDevices检测的是内置摄像头,而不是usb摄像头@Dai如何解决?如果摄像头没有显示在媒体设备API中,则这是您需要解决的驱动程序问题。如果问题是默认情况下选择了内部摄像机,请使用navigator.mediaDevices.enumerateDevices()方法查看是否还有其他摄像机可用。@ReillyGrant您能看看这个吗