Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Focus a Camera in Windows Universal Apps?

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

like image 299
Seth Kitchen Avatar asked Dec 04 '15 15:12

Seth Kitchen


People also ask

How do you focus a Windows camera?

Go back to the main view of the Camera app, and, on the left side of the window, you can see new options available, both in the “Take Photo” and “Take Video” modes. To adjust the White balance, Manual focus, Shutter speed, or Brightness, first click or tap on the setting you want to change.

How do I adjust the focus on my webcam?

Check the outer casing of your cam for a manual focus ring. This plastic ring is usually set within the frame of the cam. Turning the ring adjusts the focus, just like on a microscope or a camera lens. Not all cams have a focus ring.

How do I fix the camera focus on Windows 10?

If your Windows 10 webcam is blurry and out of focus, check your Internet connection and make sure you're not experiencing any bandwidth issues. Then, update your camera drivers, run the Hardware and Devices troubleshooter, and close background apps.

How do I get to Windows camera settings?

Open the Camera app. Swipe in from the right edge of the screen, and then select Settings. Select Options. Adjust the settings for each option.


1 Answers

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) } 
         });
like image 112
Sergii Zhevzhyk Avatar answered Oct 13 '22 22:10

Sergii Zhevzhyk