[英]Read data from USB 3.0 camera UWP
不確定我是否正確理解了這個問題。
首先,您應該在應用清單中啟用攝像頭/網絡攝像頭功能。
然后試試這個:
MediaCapture _mediaCapture = new MediaCapture();
var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
DeviceInformation deviceInfo = devices.FirstOrDefault();
if (deviceInfo == null)
deviceInfo = devices.ElementAtOrDefault(0);
var settings = new MediaCaptureInitializationSettings()
{
VideoDeviceId = deviceInfo?.Id,
PhotoCaptureSource = PhotoCaptureSource.Auto,
StreamingCaptureMode = StreamingCaptureMode.Video,
};
if (deviceInfo == null)
_mediaCapture = null;
if (_mediaCapture != null)
{
await _mediaCapture.InitializeAsync(settings);
await _mediaCapture.StartPreviewAsync();
}
編輯:
如果它不起作用並且devices
不包含您需要的相機,則應嘗試按設備ID / GUID手動查找您的設備:
// by (vendorid, deviceid)
string aqs = Windows.Devices.Usb.UsbDevice.GetDeviceSelector(0x1234, 0xabcd);
// or by device GUID
string aqs = Windows.Devices.Usb.UsbDevice.GetDeviceSelector(new Guid("camera guid"));
當你得到aqs
:
var myDevices = await DeviceInformation.FindAllAsync(aqs);
UsbDevice usbDevice = await Windows.Devices.Usb.UsbDevice.FromIdAsync(myDevices[0].Id);
// or try init MediaCaptureInitializationSettings
var settings = new MediaCaptureInitializationSettings()
{
VideoDeviceId = myDevices.FirstOrDefault()?.Id,
PhotoCaptureSource = PhotoCaptureSource.Auto,
StreamingCaptureMode = StreamingCaptureMode.Video,
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.