ARKit – 为参考图像尺寸输入的值是否重要?

ARKit – Are the values entered for Reference Image dimensions important?

在 ARKit 中,我使用参考图像的高度和宽度(由我在 AR 资源组 XCode 中输入)将相同大小的平面叠加到匹配的图像上。无论我是否输入准确的参考图像尺寸,ARKit 都会准确地将平面叠加到现实世界中(即平面正确覆盖 ARSCNView 中的匹配图像)。

如果我没理解错的话,estimatedScaleFactor 会告诉我参考图像的真实大小与我在资源组中输入的值之间的差异。

我的问题是,如果 ARKit 能够计算出参考图像中显示的对象的真实大小,when/why 我是否需要担心输入准确的高度和宽度值。

(我的参考图像是 public 艺术,有时很难准确测量它们。)

ARKit 是否必须更加努力地工作,或者是否存在如果没有准确的参考图像测量我将无法获得良好结果的情况?

附加信息:举个具体的例子,如果我要匹配电影海报,我会拍一张海报的照片,将其加载到 AR 资源组中,然后任意将宽度设置为一米左右(允许 Xcode根据图像的比例设置另一个尺寸)。

然后,当 ARKit 匹配图像时,我会在渲染器中放置一个平面(_:didAdd:for:)

let plane = SCNPlane(width: referenceImage.physicalSize.width,
    height: referenceImage.physicalSize.height)
plane.firstMaterial?.diffuse.contents = UIColor.planeColor
        
let planeNode = SCNNode(geometry: plane)
planeNode.eulerAngles.x = -.pi / 2

node.addChildNode(planeNode)

尽管我为参考图像输入的尺寸不准确,但这似乎按预期工作——平面令人信服地覆盖了匹配的图像。 (是的,estimatedScaleFactor 确实很好地近似了我的任意维度的偏差。)

所以,我想了解的是这是否会在某些情况下崩溃(以及何时,以及我需要学习什么才能理解原因!)。如果我的参考图像尺寸不准确,是否会对将平面或其他物体放置到 ARKit 提供的节点上产生负面影响?

换句话说,如果 ARKit 在没有准确的参考图像测量的情况下正确理解世界和参考图像,这是否意味着我可以不用为参考图像输入准确的测量值?

官方documentation建议:

The default value of estimatedScaleFactor (a factor between the initial size and the estimated physical size) is 1.0, which means that a version of this image that ARKit recognizes in the physical environment exactly matches its reference image physicalSize. Otherwise, ARKit automatically corrects the image anchor's transform when estimatedScaleFactor is a value other than 1.0. This adjustment in turn, corrects ARKit's understanding of where the image anchor is located in the physical environment.

var estimatedScaleFactor: CGFloat { get }

为了更精确地缩放 3D 模型,您需要测量真实世界的图像,当 AR 应用 运行 时,ARKit 会测量其可观察到的参考图像。 ARImageAnchor 存储了 estimatedScaleFactor 属性 的值,因此 ARKit 记录了比例因子的差异,然后它将新的比例应用于 3D 模型,你的模型变大或变小,即 estimatedScaleFactor 是为了.


但是,有一个自动方法:

To accurately recognize the position and orientation of an image in the AR environment, ARKit must know the image's physical size. You provide this information when creating an AR reference image in your Xcode project's asset catalog, or when programmatically creating an ARReferenceImage.

When you want to recognize different-sized versions of a reference image, you set automaticImageScaleEstimationEnabled to true, and in this case, ARKit disregards physicalSize.

var automaticImageScaleEstimationEnabled: Bool { get set }