Auto focus camera without preview
Asked Answered
C

3

6

I am running Win10 IoT on a pi 2. I need to be able to take pictures that are focused but cannot get the focus working. The application is a background app so I don't have a way of previewing the camera on a display. Is there any way of doing this? Currently I have

await _mediaCapture.StartPreviewAsync();
_mediaCapture.VideoDeviceController.FocusControl.Configure(new FocusSettings
{
    Mode = FocusMode.Continuous,
    WaitForFocus = true
});
await _mediaCapture.VideoDeviceController.FocusControl.FocusAsync();
await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
await _mediaCapture.StopPreviewAsync();

but I am getting the error

WinRT information: Preview sink not set

when I try to focus. All of the examples I've seen online show that the preview is output to a control and I assume it wires a sink up automagically. Is there a way to do this manually through code? Possibly without the preview?

Comradery answered 8/3, 2016 at 20:19 Comment(0)
C
0

I didn't find a way to do this. I ended up converting the background app to a UI app with a Page containing a CaptureElement control in order to preview and focus.

Comradery answered 7/4, 2016 at 20:38 Comment(0)
P
0

I wonder if the code may work even without FocusControl.

I propose you follow Customer Media Sink implementation example and use of StartPreviewToCustomSinkIdAsync method described at http://www.codeproject.com/Tips/772038/Custom-Media-Sink-for-Use-with-Media-Foundation-To

Pimentel answered 29/3, 2016 at 18:26 Comment(0)
C
0

I didn't find a way to do this. I ended up converting the background app to a UI app with a Page containing a CaptureElement control in order to preview and focus.

Comradery answered 7/4, 2016 at 20:38 Comment(0)
L
0

Instead of adding a UI, just create a CaptureElement and set the source to the _mediaCapture before calling await _mediaCapture.StartPreviewAsync();

Something like:

  _captureElement = new CaptureElement { Stretch = Stretch.Uniform };
  _mediaCapture = new MediaCapture();

  await _mediaCapture.InitializeAsync(...);

  _captureElement.Source = _mediaCapture;
  await _mediaCapture.StartPreviewAsync();
Linders answered 16/6, 2018 at 2:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.