簡體   English   中英

從USB 3.0相機UWP讀取數據

[英]Read data from USB 3.0 camera UWP

我正在使用USB 3.0相機顯示其預覽屏幕。 但是似乎Windows無法識別它是Imaging Device,因此當我嘗試打開W​​indows 10的默認相機應用程序時,它顯示了錯誤。 因此,我的問題是如何將USB 3.0相機像成像設備那樣帶入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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM