如何实现垂直平面检测(即墙壁)?
let configuration = ARWorldTrackingSessionConfiguration()
configuration.planeDetection = .horizontal //TODO
编辑:现在支持ARKit 1.5(iOS 11.3)。只需使用.vertical
。出于历史目的,我保留了上面的帖子。
垂直平面检测不是(现在)ARKit中存在的特征。 .horizontal
建议可以使用此功能,并可能在将来添加。如果它只是一个布尔值,这表明它是最终的。
我在WWDC17与一位Apple工程师进行的一次对话证实了这种怀疑。
您可能会争辩说,为此创建实现将是困难的,因为对于垂直平面而不是水平平面有更多的方向,但正如Rodamn所说,情况可能并非如此。
来自rodamn的评论:最简单的是,一架飞机被定义为三个共面点。一旦沿表面检测到足够的检测到的共面特征(垂直,水平或任意角度),就有一个表面候选者。只是水平线的法线将沿着上/下轴,而垂直法线将平行于地平面。挑战在于,朴素的干墙往往产生很少的视觉特征,而平坦的墙壁往往不会被发现。我强烈怀疑这就是为什么.vertical
功能尚未发布的原因。
但是,这有一个反驳的论点。有关更多信息,请参阅rickster的评论。
iOS 11.3将支持此功能:
static var vertical: ARWorldTrackingConfiguration.PlaneDetection
会话检测与重力平行的表面(无论其他方向如何)。
https://developer.apple.com/documentation/arkit/arworldtrackingconfiguration.planedetection https://developer.apple.com/documentation/arkit/arworldtrackingconfiguration.planedetection/2867271-vertical
Apple发布的iOS 11.3将针对AR提供各种更新,包括ARKit 1.5。在此更新中,ARKit包括ARKit识别虚拟对象并将其放置在墙壁和门等垂直表面上的功能。
ARWorldTrackingConfiguration现在支持垂直支持
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = [.horizontal, .vertical]
sceneView.session.run(configuration)
由于iPhone X采用了前置式深度摄像头,我怀疑是朝向后者将会出现在下一个版本中,并且可能会在此之前委托.vertical
功能。
我用Unity做了,但我需要做数学。
我使用Random Sample Consensus来检测ARkit返回的点云的垂直平面。这就像有一个循环随机选取3个点来创建一个平面并计算与之匹配的点,并看看哪个尝试是最好的。
它正在发挥作用。但是因为当墙壁是纯色时,ARkit不能返回很多点。所以它在许多情况下都不起作用。
据说苹果公司正致力于为新款iPhone提供额外的AR功能,即为相机提供额外的传感器。当这些设备功能已知时,这可能是一个功能。这里有一些猜测。 http://uk.businessinsider.com/apple-iphone-8-rumors-3d-laser-camera-augmented-reality-2017-7和另一个来源https://www.fastcompany.com/40440342/apple-is-working-hard-on-an-iphone-8-rear-facing-3d-laser-for-ar-and-autofocus-source
在ARKit 1.0中,只有
.horizontal
枚举用于检测水平表面(如桌子或地板)的情况。在ARKit 1.5及更高版本中,.horizontal
结构的.vertical
和PlaneDetection
属性符合OptionSet
协议。
要在ARKit 2.0中实现垂直平面检测,请使用以下代码:
configuration.planeDetection = ARWorldTrackingConfiguration.PlaneDetection.vertical
或者您可以对两种类型的平面使用检测:
private func configureSceneView(_ sceneView: ARSCNView) {
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = [.horizontal, .vertical] //BOTH TYPES
configuration.isLightEstimationEnabled = true
sceneView.session.run(configuration)
}
您还可以添加ARSceneManager
扩展来处理委托调用:
extension ARSceneManager: ARSCNViewDelegate {
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let planeAnchor = anchor as? ARPlaneAnchor else {
return
}
print("Found plane: \(planeAnchor)")
}
}