3

I am developing an application for Windows 10 phone on Universal Windows Platform. I need to get a frame from the devices camera and do some processing; this is supposed to happen in the background, the user is not supposed to see the camera feed anywhere in the UI.

There are two classes that handle the most common use cases, namely CameraCaptureUI and MediaCapture. The MediaCapture class allows to grab the so called preview frame but the whole workflow revolves around binding a MediaCapture instance to a UI control (ie CaptureElement) and if I do not do it then I am unable to get the preview frames. This makes the MediaCapture class unsuitable for my case unless there is another way to use it that I am not aware of.

An answer to a related question How to get preview buffer of MediaCapture - Universal app suggests usage of Lumia Imaging SDK but it is targeted at Windows 8 family and the classes and methods used there are now deprecated in the current Lumia Imaging SDK for Windows 10.

Additionaly, the aforementioned answer brings up custom media sinks but I am unsure if that can help me in my scenario and if yes, then where should I start.

To sum up, how do I acquire frames from a camera device that can be used for further processing in a Windows 10 universal app?

Community
  • 1
  • 1
Bartosz
  • 732
  • 9
  • 30

2 Answers2

1

There are multiple options available to you for this. CameraCaptureUI is not one of them.

Once you've done that, you can take photos or just get preview frames. The CameraStarterKit will teach you the former, CameraGetPreviewFrame will teach you the latter.

Mike
  • 2,220
  • 1
  • 18
  • 32
  • Wondering if it does work indeed if you don't add it to the layout at all (e.g. create it in code or have Visibility.Hidden instead of Collapsed, if there's such a thing in UWP too as there was in WPF) – George Birbilis Aug 24 '17 at 12:09
  • Why are you wondering, have you seen it not work? Regardless, there is now the CameraFrames SDK sample that shows how to use an API designed to deliver the frames to you using a FrameReader. This may be the more appropriate solution for this use case, and it can handle more complex camera sensors, like the ones used by Windows Hello. Link: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CameraFrames – Mike Dec 29 '17 at 16:23
  • the reason I'm wondering is cause in some UI technologies you need to add something to the visual tree (even if invisible) for it to get a native peer – George Birbilis Jan 10 '18 at 10:27
  • was helping a friend resolve some issues he had with his code - we ended up using a CaptureElement and it did work fine - https://github.com/Zoomicon/MjpegStreamer/blob/master/UWP/CameraStreamer.UWP/CameraCapture.cs – George Birbilis Jan 10 '18 at 10:30
0

How about you put a CaptureElement in UI, but hide it with overlay or set width / height to 1 ? Its kind of a hack but it will provide you the frame.

thang2410199
  • 1,932
  • 2
  • 17
  • 18