我正在使用c#和xaml开发一个metro风格的应用程序。对于特定任务,我需要检测当前捕获的凸轮(正面或背面)。有没有办法检测winrt中的前凸轮或后凸轮。请帮帮我。
答案 0 :(得分:1)
使用DeviceInformationCollection上的索引不是一个可靠的解决方案:
遇到与你相同的问题是我如何解决它:
// Still need to find all webcams
DeviceInformationCollection webcamList = await eviceInformation.FindAllAsync(DeviceClass.VideoCapture)
// Then I do a query to find the front webcam
DeviceInformation frontWebcam = (from webcam in webcamList
where webcam.EnclosureLocation != null
&& webcam.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front
select webcam).FirstOrDefault();
// Same for the back webcam
DeviceInformation backWebcam = (from webcam in webcamList
where webcam.EnclosureLocation != null
&& webcam.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back
select webcam).FirstOrDefault();
在这个例子中,我使用了Linq查询,但它与foreach on" webcamList"的工作方式相同。
只需在每个DeviceInformation上查看 .EnclosureLocation.Panel 属性,该属性是 Windows.Devices.Enumeration.Panel 枚举。剩下的就是obvius,Front用于前置摄像头,Back用于后置摄像头。
还要小心检查 .EnclosureLocation 是否为空,使用USB网络摄像头大部分时间似乎都为空。
答案 1 :(得分:0)
您可以使用此代码。
DeviceInformationCollection videoCaptureDevices = await eviceInformation.FindAllAsync(DeviceClass.VideoCapture);
如果videoCaptureDevices计数为零,则表示没有连接相机 如果摄像机数量是2,那么Front&后置摄像头。
如果您使用videoCaptureDevices [0]
初始化相机操作,则会使用前置摄像头,如果正在使用videoCaptureDevices [1]
,则会返回后置摄像头。