0

我的使用网络摄像头扫描 QR 码图像的 UWP 商店应用在某些笔记本电脑上无法运行。我正在使用 MediaCapture 类进行预览和扫描。我收到了来自不同用户的报告,某些设备在应用程序中没有显示任何图像(并且没有错误消息),而其他设备则很好地显示了相机预览。以下是帮助缩小问题所在范围的设备列表。其中一些我通过进入展示笔记本电脑的大型零售商进行了测试。

这些工作:

  • 戴尔 E5450(自己测试过)
  • 联想u310(亲测)
  • 带有附加网络摄像头的联想 u310(我自己测试过)
  • 联想平板(用户报告,未验证,有多个摄像头)
  • HP Elitebook 850 g5(我自己测试过,有 Windows Hello)
  • 多台通用高端笔记本电脑

这些不起作用:

  • Surface Go(用户报告,本人验证,有 Windows Hello)
  • Surface 笔记本电脑(由用户报告,不确定哪个型号有 Windows Hello)
  • Dell Latitude 7275(用户报告,未经验证,具有实感摄像头)

最初,我认为这是由于连接了多个相机或它们的分辨率较高造成的,但经过更多的报告和测试,我认为可能是这些“特殊”相机造成了麻烦。

这是初始化代码:

mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
List<VideoEncodingProperties> availableResolutions = null;
try { 
    availableResolutions = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Where(properties=>properties is VideoEncodingProperties).Select(properties=>(VideoEncodingProperties)properties).ToList();
}
catch(Exception ex)
{
    MessageManager.ShowMessageToUserAsync("No resolutions could be detected, trying default mode.");
}
VideoEncodingProperties bestVideoResolution = this.findBestResolution(availableResolutions);
VideoEncodingProperties bestPhotoResolution = this.findBestResolution(availableResolutions);
if (bestVideoResolution != null)
{
    await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, bestVideoResolution);
}
if (bestPhotoResolution != null)
{
    await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, bestPhotoResolution);
}
displayRequest.RequestActive();
DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
previewWindowElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();

整个文件在这里: https ://github.com/matthiasduyck/WifiQRCodeReader/blob/b774cbca4f9dc58f9aed53ebdb827666f4924bb2/Wifi%20QR%20code%20scanner/Managers/QRCameraManager.cs

这是商店中当前修订版的完整项目: https ://github.com/matthiasduyck/WifiQRCodeReader/tree/b774cbca4f9dc58f9aed53ebdb827666f4924bb2

这是商店中的应用程序: https ://www.microsoft.com/en-us/p/wifi-qr-code-scanner/9pnhnrbg9wlh

有谁知道发生了什么以及我如何解决这个问题?

编辑:我已更新应用程序以尝试过滤掉非彩色相机(深度、红外线等)。看起来我更新的代码没有正确执行此操作。这是尝试仅查找所有彩色相机的代码:

var videoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
var groups = await MediaFrameSourceGroup.FindAllAsync();

// Filter out color video preview and video record type sources and remove duplicates video devices.
var _frameSourceGroups = groups.Where(g => g.SourceInfos.Any(s => s.SourceKind == MediaFrameSourceKind.Color &&
                        (s.MediaStreamType == MediaStreamType.VideoPreview || s.MediaStreamType == MediaStreamType.VideoRecord))
                        && g.SourceInfos.All(sourceInfo => videoDevices.Any(vd => vd.Id == sourceInfo.DeviceInformation.Id))).ToList();
availableColorCameras = _frameSourceGroups.SelectMany(x => x.SourceInfos.Select(y => y.DeviceInformation));

这是使用 windows hello 样式相机的用户得到的下拉列表: 相机下拉选项,列出了 6 个相机

4

0 回答 0