RealityKit 中使用的相机的真实焦距是多少?

What is the real Focal Length of the camera used in RealityKit?

我正在从 Xcode 的默认 AR 项目开始做这个增强现实项目。

我需要知道 ARKit 使用的相机的焦距。

This page很好地定义了焦距:

Focal length, usually represented in millimeters (mm), is the basic description of a photographic lens. It is not a measurement of the actual length of a lens, but a calculation of an optical distance from the point where light rays converge to form a sharp image of an object to the digital sensor or 35mm film at the focal plane in the camera. The focal length of a lens is determined when the lens is focused at infinity.

说的是,Apple 提供了这种称为 intrinsics 的相机矩阵,定义为

根据 Apple 的说法,

The values fx and fy are the pixel focal length, and are identical for square pixels. The values ox and oy are the offsets of the principal point from the top-left corner of the image frame. All values are expressed in pixels.

我得到 fxfy 相同的数字,即 1515.481

要获得以毫米为单位的真实焦距,

  1. This page 说我需要使用这个公式:F(mm) = F(pixels) * SensorWidth(mm) / ImageWidth (pixel) 但我没有传感器尺寸。
  2. this other pageFC = fx/sx = fy/sy,其中 sxsy 是图像尺寸宽度和高度,我想会给我两个数字,因为 fx = fy...这又回到了零。

在 iPhone 11 上,ARCamera 捕获了具有以下尺寸的帧:1920x1440,至少此数字由 属性 camera.imageResolution.

报告

以精神健康的名义,有没有办法得到 RealityKit 使用的 ARCamera 的焦距?

ARKit 和 RealityKit 确实具有相同的 focal length 参数值。那是因为这两个框架应该一起工作。尽管目前 ARView 没有 focal length 实例 属性,但您可以在控制台中轻松地为 ARSCNViewSCNView 打印 focal length

@IBOutlet var sceneView: ARSCNView!

sceneView.pointOfView?.camera?.focalLength

但是,考虑到 ARKit、RealityKit 和 SceneKit 框架不使用 屏幕分辨率,它们而是使用 。 iPhones 视口的放大倍数通常是 1/21/3.


内在相机矩阵

正如您在 ARKit 中所说,有一个 3x3 相机矩阵允许您在 2D 相机平面和 3D 世界坐标之间转换 space。

var intrinsics: simd_float3x3 { get }

使用此矩阵可以打印 4 个重要参数:fxfyoxoy。让我们将它们全部打印出来:

DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
                    
    print(" Focal Length: \(self.sceneView.pointOfView?.camera?.focalLength)")
    print("Sensor Height: \(self.sceneView.pointOfView?.camera?.sensorHeight)")
    // SENSOR HEIGHT IN mm
                    
    let frame = self.sceneView.session.currentFrame

    // INTRINSICS MATRIX
    print("Intrinsics fx: \(frame?.camera.intrinsics.columns.0.x)")
    print("Intrinsics fy: \(frame?.camera.intrinsics.columns.1.y)")
    print("Intrinsics ox: \(frame?.camera.intrinsics.columns.2.x)")
    print("Intrinsics oy: \(frame?.camera.intrinsics.columns.2.y)")
}

对于 iPhone X,打印以下值:

当你应用你的公式时,你会得到一个难以置信的结果(继续阅读以找出原因)。


关于广角镜头和光学防抖

The iPhone X has two rear camera sensors, and both those modules are equipped with an optical image stabilizer (OIS). The wide-angle lens offers a 28-millimeter focal length and an aperture of f/1.8, while the telephoto lens is 56 millimeters and f/2.4.

ARKit和RealityKit使用广角镜头后置模块。在 iPhone X 情况下,它是 28 毫米镜头。但是打印值 focal length = 20.78 mm 呢?我认为 28 mm20.78 mm 的值之间的差异是由于视频稳定占用了大约 25% 的图像总面积。这样做是为了最终获得最终图像的焦距值 28 mm

红框为稳定阶段裁剪边距


结论

这是我自己的结论。我没有找到关于那个主题的任何参考资料,所以如果我的观点有误,请不要严厉批评我(我承认可能是).

众所周知,相机抖动会随着焦距的增加而放大。因此,焦距值越小,相机抖动越小。这对于 AR 应用程序中无抖动的高质量世界跟踪非常重要。此外,我坚信光学图像稳定器在较低的焦距值下效果更好。因此,ARKit 工程师为 AR 体验选择较低的 focal length 值(捕获更宽的图像区域)也就不足为奇了,然后在稳定之后,我们得到图像的修改版本,就像它有 focal length = 28 mm.

因此,以我的愚见,为 RealityKit 和 ARKit 计算一个真实的 focal length 是没有意义的,因为苹果工程师已经实现了一个“假的”focal length增强现实体验。