如何计算 AVCaptureDevice 的 focusPointOfInterest?

发布于 2024-09-14 13:21:25 字数 219 浏览 8 评论 0原文

如何计算给定 AVCaptureDevice 的 focusPointOfInterest(0,0 和 1,1 之间的 CGPoint 值)?

我一直在关注最新 WWDC 的代码示例,但我真的不明白如何进行计算。另外,我的应用程序处于横向与纵向(如示例中所示)...因此,除了不了解如何计算事物之外,我不确定需要进行哪些调整才能考虑横向方向。

任何帮助将不胜感激。

谢谢-wg

How do you calculate the focusPointOfInterest (a CGPoint value between 0,0 and 1,1) for an given AVCaptureDevice?

I've been following the code samples from the latest WWDC but I really don't understand how to calculation is being made. Also, my application is sitting in landscape vs. portrait (as in the sample) ... so in addition to not understanding how things are being calculated, I'm not sure what adjustments I need to make in order to account for landscape orientation.

Any help would be appreciated.

Thanks - wg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你穿错了嫁妆 2024-09-21 13:21:25

根据 http://developer.apple。 com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/03_MediaCapture.html

您传递一个 CGPoint,其中 {0,0} 表示图片区域的左上角,而 {1,1} 表示横向模式下的右下角,主页按钮位于右侧 - 即使设备处于在纵向模式下。

According to http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/03_MediaCapture.html:

You pass a CGPoint where {0,0} represents the top left of the picture area, and {1,1} represents the bottom right in landscape mode with the home button on the right—this applies even if the device is in portrait mode.

对不⑦ 2024-09-21 13:21:25

如果您有 AVCaptureVideoPreviewLayer ,则可以使用 captureDevicePointOfInterestForPoint 以便转换通过点击手势获得的 CGPoint

这样您就不必担心方向问题。

If you have an AVCaptureVideoPreviewLayer, you can use captureDevicePointOfInterestForPoint in order to convert the CGPointyou get with a tap gesture.

That way you just don't have to worry about orientation.

淡墨 2024-09-21 13:21:25

您可以通过执行以下操作将点从屏幕坐标旋转到相机坐标:(焦点从 0,0 到 1,1)

let interfaceOrientation = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.interfaceOrientation
switch interfaceOrientation {
case .landscapeLeft:
    return focusPoint
case .landscapeRight:
    return .init(x: 1 - focusPoint.x, y: 1 - focusPoint.y)
case .portraitUpsideDown:
    return .init(x: 1 - focusPoint.y, y: focusPoint.x)
default:
    return .init(x: focusPoint.y, y: 1 - focusPoint.x)
}

You can rotate the point from screen coordinate to camera coordinate by doing this: (focusPoint is from 0,0 to 1,1)

let interfaceOrientation = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.interfaceOrientation
switch interfaceOrientation {
case .landscapeLeft:
    return focusPoint
case .landscapeRight:
    return .init(x: 1 - focusPoint.x, y: 1 - focusPoint.y)
case .portraitUpsideDown:
    return .init(x: 1 - focusPoint.y, y: focusPoint.x)
default:
    return .init(x: focusPoint.y, y: 1 - focusPoint.x)
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文