How to display the preview of 2 cameras in windows 8 using the MediaCapture class

你说的曾经没有我的故事 提交于 2019-12-10 11:49:04

问题


I want to be able to show the preview of several camera devices using the MediaCapture class. Currently I initialize the MediaCapture with a MediaCaptureInitializationSettings object which contains the device id. The settings object receives only 1 VideoDeviceId so I cannot set several video sources for the same MediaCapture object. Another thing I tried was to create several MediaCapture objects, one per device. However, it looks like the last one that gets initialized is the one who gets the device access, so even when there are several media devices each one associated to a different device, only the video of one of the devices is allowed to be displayed as a preview.

Below is the code so that you can have a better understanding.

async private void PreviewDevice(string deviceId)
{
    var mediaCapture = new MediaCapture();
    var mediaCaptureSettings = new MediaCaptureInitializationSettings
    {
        VideoDeviceId = deviceId
    };
    await mediaCapture.InitializeAsync(mediaCaptureSettings);
    var previewElement = new CaptureElement
    {
        Source = mediaCapture
    };
    CamerasDisplayGrid.Children.Add(previewElement);
    await mediaCapture.StartPreviewAsync();
}

What I want to achieve is to get the preview of several cameras in the screen at the same time.

Please advice. Thank you in advance


回答1:


maybe this link can help: http://social.msdn.microsoft.com/Forums/sr-Cyrl-CS/winappswithcsharp/thread/13d2ce8f-de6d-47c0-8992-4d443a49326f

It's theoretically possible from an application perspective, but there are hardware limitations also in place.




回答2:


I had the same problem and here is what I did:

  1. Create a canvas object
  2. Insert in that canvas object as many capture elements as I wanted
  3. Enumerate all the cameras available with DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
  4. Associate every camera id that i find with a capture element.
  5. Deploy.

However, when I run the app starting with vs 11 it only shows one active camera, but, when I run it from start menu, it shows me all the cameras I have.



来源:https://stackoverflow.com/questions/13826839/how-to-display-the-preview-of-2-cameras-in-windows-8-using-the-mediacapture-clas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!