c# - 如何在 Windows 通用应用程序中对焦相机?

标签 c# camera uwp autofocus

我正在使用位于此处的 Windows 通用 OCR 示例:

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

特别是 OcrCapturedImage.xaml.cs

相机似乎经常变得不对焦、模糊,并且远不及 native 相机应用程序的质量。如何设置自动对焦和/或点击以修复曝光?

到目前为止,我尝试过查看有助于设置分辨率的其他相机样本,但我找不到任何关于对焦/曝光的信息。

更新:

我觉得

await mediaCapture.VideoDeviceController.FocusControl.FocusAsync();

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

但这是行不通的(什么都不做 - 仍然模糊等),如果有人知道如何点击某个区域并相应地应用焦点/曝光,则可以在此基础上构建。

原生相机:

enter image description here

应用相机:

enter image description here

根据答案更新:

我一定是将焦点方法放在了错误的位置,因为我的原始更新代码有效。 Sergi 的也有效。我想结合使用点击事件,如下所示:

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

但是它抛出的参数不正确。另外,我如何在预览屏幕上显示一个矩形叠加层,以便用户知道感兴趣的区域有多大?

这是一个很棒的链接 https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/CameraManualControls/cs/MainPage.Focus.xaml.cs

最佳答案

使用 Configure 配置自动对焦FocusControl 类的方法。

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

为了专注于某个领域,RegionOfInterestControl可以使用属性。它有 SetRegionsAsync添加 RegionOfInterest 集合的方法实例。 RegionOfInterestBounds定义焦点区域的属性。此示例显示如何将焦点设置在中心:

// 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) } 
         });

关于c# - 如何在 Windows 通用应用程序中对焦相机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34091390/

相关文章:

c# - 仅在后台操作较长时显示进度

c# - 如何按日、周、月自动发送邮件?

iphone - App Store:我可以将我的应用程序下载限制在仅限相机的设备上吗?

c# - BitmapImage 到字节数组,反之亦然

c# - UWP richeditbox打印多页

带复选框的 C# 文件浏览

c# - 机器人 channel 注册 SocketException - 远程主机强制关闭现有连接

android - 将从相机拍摄的图像设置为 ImageView

ios - 从后台应用程序拍摄前置摄像头照片

win-universal-app - 是否可以在 UWP 中获取用户编写的 RichEditBox 文本?