【问题标题】:Reset ARSCNView background contents to its original source将 ARSCNView 背景内容重置为其原始来源
【发布时间】:2020-07-11 09:09:31
【问题描述】:

我正在捕获 ARFrame 并应用过滤器,效果很好,但我想关闭过滤器并返回原始相机源,但我遇到了问题。此代码正在应用过滤器:

 func session(_ session: ARSession, didUpdate frame: ARFrame) {
  let filterImage = setFilter(session.currentFrame)
  sceneView.scene.background.contents = context.createCGImage(filterImage, from: filterImage.extent)
 }

一旦我设置了sceneView.scene.background.contents,我就无法将其设置回原始来源。原始来源是一个名为:SCNCaptureDeviceOutputConsumerSource 的对象,它不在文档中。我尝试保存该对象并再次使用它设置背景内容,但它只会显示它所持有的最后一帧(因此会有静止图像)。它不会持续更新。我不知道如何让sceneView.scene.background.contents 从与替换之前相同的源中提取数据。

我尝试设置sceneView.session.delegate = nil,但这不起作用,它只是停止更新,并且屏幕看起来像冻结了一样。

有没有办法将 ARSCNView 背景内容重置为其获取数据的原始来源?

如果我重新加载 ARSCNView,它可以工作,但重新加载至少需要一秒半:

   sceneView.session.delegate = nil
   sceneView = nil
   sceneView = ARSCNView(frame: view.bounds)
   view.addSubview(sceneView)
   sceneView.delegate = self
   sceneView.session.run(ARFaceTrackingConfiguration())

感谢您提供的任何帮助。

【问题讨论】:

    标签: ios swift augmented-reality arscnview


    【解决方案1】:

    我是 Stackoverflow 帖子的新手,如果这个答案的质量不是那么高,那就是它的原因。我和你有同样的问题。这是我修复它的方法。

    首先将sceneView.scene.background.contents 设置为变量。 然后您可以将sceneView.scene.background.contents 更改为例如UIColor.lightGray

    如果您想将其重置为原始来源,只需执行以下操作即可。

    sceneView.scene.background.contents = originalSource
    

    请确保不要更改变量 originalSource,因为这样您将删除您的 originalSource。

    希望这有帮助,

    最好的问候

    【讨论】:

    猜你喜欢
    • 2018-08-29
    • 1970-01-01
    • 2021-03-14
    • 2014-11-15
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    相关资源
    最近更新 更多