9

I am working with the Windows Universal Sample for OCR located here:

https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/OCR/cs

Specifically the OcrCapturedImage.xaml.cs

It seems that the camera often becomes unfocused, blurry, and nowhere near as good quality as the native camera app. How can I set up autofocusing and/or tap to fix exposure?

What I have tried so far is looking at the other camera samples which help set resolution, but I cannot find anything about focus/exposure.

Update:

I think

await mediaCapture.VideoDeviceController.FocusControl.FocusAsync();

and

await mediaCapture.VideoDeviceController.ExposureControl.SetAutoAsync(true);

But this isn't working (does nothing-still blurry etc.) and could be built upon if someone knows how to tap a certain area and apply focus/exposure accordingly.

Native Camera:

enter image description here

App Camera:

enter image description here

Update based on answer:

I must have been putting my focus methods in the wrong spot because my original update code works. Sergi's also works. I want to used the tapped event in combination with it, something like this:

Point tapped=e.GetPosition(null); //Where e is TappedRoutedEventArgs from a tapped event method on my preview screen
await mediaCapture.VideoDeviceController.RegionsOfInterestControl.ClearRegionsAsync();
await mediaCapture.VideoDeviceController.RegionsOfInterestControl.SetRegionsAsync(new[] { new RegionOfInterest() { Bounds = new Rect(tapped.X, tapped.Y, 0.02, 0.02) } }); //Throws Parameter Incorrect

But it throws parameter incorrect. Also, How would I show the overlay a Rectangle on the preview screen, so the user knows how big the region of interest is?

This is a great link https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/CameraManualControls/cs/MainPage.Focus.xaml.cs

Seth Kitchen
  • 1,526
  • 19
  • 53
  • I don't see `CapturedImage.cs` in the page you're linking. – Jeremy Dec 04 '15 at 21:20
  • @Nick My bad OcrCapturedImage.xaml.cs. I updated – Seth Kitchen Dec 04 '15 at 21:23
  • Could you please check whether focusing is available using these two properties `mediaCapture.VideoDeviceController.FocusControl.Supported` and `mediaCapture.VideoDeviceController.Focus.Capabilities.Supported`? – Sergii Zhevzhyk Dec 07 '15 at 16:38
  • 2
    you could als try to [cofigure the focus](https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.media.devices.focuscontrol.configure.aspx), for example, `mediaCapture.VideoDeviceController.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Auto });` and then call `await mediaCapture.VideoDeviceController.FocusControl.FocusAsync();` – Sergii Zhevzhyk Dec 07 '15 at 16:47
  • 1
    @SergiiZhevzhyk Your last suggestion works. If you can add on to it by Focusing a certain point on the preview screen I would appreciate it. What I mean is on the native camera you can tap anywhere, and the focus and exposure will be set to that area – Seth Kitchen Dec 07 '15 at 17:15
  • 1
    Could you pleas try to setup the [RegionOfInterestControl](https://msdn.microsoft.com/en-us/library/windows.media.devices.videodevicecontroller.regionsofinterestcontrol.aspx)? `The region of interest selects the area of preview that functions such as focus and exposure are computed over. This enables scenarios such as tap to focus.`. – Sergii Zhevzhyk Dec 07 '15 at 17:42
  • 1
    @SergiiZhevzhyk Yes these look correct. If you write up an answer with both of these I will accept – Seth Kitchen Dec 07 '15 at 17:49
  • @SethKitchen I've added the answer. I'm not able to test this code now so if you have any comments please let me know. – Sergii Zhevzhyk Dec 07 '15 at 19:06

1 Answers1

8

Configuration of the auto focus using the Configure method of the FocusControl class.

mediaCapture.VideoDeviceController.FocusControl.Configure(
    new FocusSettings { Mode = FocusMode.Auto });
await mediaCapture.VideoDeviceController.FocusControl.FocusAsync();

In order to focus on a certain area, the RegionOfInterestControl propery can be used. It has the SetRegionsAsync method to add a collection of RegionOfInterest instances. RegionOfInterest has the Bounds property which defines the region of focus. This example shows how to set the focus in the center:

// clear previous regions of interest
await mediaCapture.VideoDeviceController.RegionOfInterestControl.ClearRegionsAsync();
// focus in the center of the screen
await mediaCapture.VideoDeviceController.RegionOfInterestControl.SetRegionsAsync(
    new [] 
         { 
             new RegionOfInterest() {Bounds = new Rect(0.49,0.49,0.02,0.02) } 
         });
Sergii Zhevzhyk
  • 4,074
  • 22
  • 28
  • I have marked your answer as correct, but there are a couple things that could be added that I have listed in an update in my question. I will award the bounty if no other answers are better at the end of the time frame – Seth Kitchen Dec 07 '15 at 19:39
  • I fixed parameter incorrect by adding AutoFocusEnabled=true, AutoExposureEnabled=true, AutoWhiteBalanceEnabled=true, BoundsNormalized=true, Type=RegionofInterestType.Unknown, and Weight=100 to my Roi instead of just Bounds. Now I get argument out of range. Either my point or size must be incorrect – Seth Kitchen Dec 07 '15 at 20:36