在下面的代码片段中我们看到personSegmentationWithDepth
深度合成的 type 属性(有 RGB、Alpha 和 Depth 通道):
// Automatically segmenting and then compositing foreground (people),
// middle-ground (3D model) and background.
let session = ARSession()
if let configuration = session.configuration as? ARWorldTrackingConfiguration {
configuration.frameSemantics.insert(.personSegmentationWithDepth)
session.run(configuration)
}
您可以手动访问 CVPixelBuffer 中世界跟踪的深度数据(执行分割的深度值):
let image = frame.estimatedDepthData
您可以手动访问 CVPixelBuffer 中面部跟踪的深度数据(来自 TrueDepth 相机):
let image = session.currentFrame?.capturedDepthData?.depthDataMap
另外,还有一个generateDilatedDepth
ARKit 3.0中的实例方法:
func generateDilatedDepth(from frame: ARFrame,
commandBuffer: MTLCommandBuffer) -> MTLTexture
在你的情况下你必须使用estimatedDepthData
因为苹果文档说:
它是一个缓冲区,表示用于遮挡虚拟内容的相机输入的估计深度值。
var estimatedDepthData: CVPixelBuffer? { get }
如果你乘以DEPTH
来自此缓冲区的数据(首先您必须将深度通道转换为 RGB)RGB
or ALPHA
using 合成技术 https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CISourceOverCompositing你会得到很棒的效果。
看这 6 个图像:下面一行代表使用深度通道校正的三个 RGB 图像:深度分级、深度模糊、深度点位置传递。