I'm capturing ARFrame's and applying filters, which works fine, but I want to turn off the filters and go back to the original camera feed, but I'm running into issues. This code is applying the filter:
func session(_ session: ARSession, didUpdate frame: ARFrame) {
let filterImage = setFilter(session.currentFrame)
sceneView.scene.background.contents = context.createCGImage(filterImage, from: filterImage.extent)
}
Once I set sceneView.scene.background.contents
, I cannot set it back to the original source. The original source is an object called: SCNCaptureDeviceOutputConsumerSource, which is not in the documentation. I tried saving that object and setting the background contents with it again, but it will just display the last frame it was holding (so there will be a still image). It does not continuously update. I don't know how to make sceneView.scene.background.contents
extract data from the same source as it was before I replaced it.
I tried setting sceneView.session.delegate = nil
, but that did not work, it just stops updating, and the screen looks like it freezes.
Is there a way to reset ARSCNView background contents to the original source it was getting data from?
If I reload the ARSCNView, it works, but it takes at least a second and a half to reload:
sceneView.session.delegate = nil
sceneView = nil
sceneView = ARSCNView(frame: view.bounds)
view.addSubview(sceneView)
sceneView.delegate = self
sceneView.session.run(ARFaceTrackingConfiguration())
Thank you for any help you can give.
I'm new to Stackoverflow posting, If the quality of this answer isn't that high, that is the reason for it. I had the same problem as you. Here's how I fixed it.
First set the
sceneView.scene.background.contents
as a variable. Then you can change thesceneView.scene.background.contents
to for exampleUIColor.lightGray
.If you want to reset it back to its original Source, just do as follows.
Just make sure to not change the variable
originalSource
, because then you are deleting your originalSource.Hope this helped,
Best Regards