Since ARKit3 it is possible to run a ARSession() that supports the back and front camera simultaneously.
For example this creates an ARConfiguration for the front camera that supports also Worldtracking.
// session for the front camera
let configuration = ARFaceTrackingConfiguration()
configuration.isWorldTrackingEnabled
sceneView.session.run(configuration)
This example creates a configuration for a back camera session with Face Tracking enabled:
// session for the back camera
let configuration = ARWorldTrackingConfiguration()
configuration.userFaceTrackingEnabled = true
sceneView.session.run(configuration)
I would like to create 2 independent ARConfigurations and ARSessions that run simultaneously. Like this:
So far i tried this code:
import UIKit
import SceneKit
import ARKit
class ViewController: UIViewController, ARSCNViewDelegate {
// back camera view
@IBOutlet var backView: ARSCNView!
// front camera view
@IBOutlet weak var frontView: ARSCNView!
override func viewDidLoad() {
super.viewDidLoad()
// Set the view's delegate
sceneView.delegate = self
frontView.delegate = self
// Create a new scene for back camera
let scene = SCNScene(named: "art.scnassets/ship.scn")!
backView.scene = scene
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// session for the back camera
let configuration = ARWorldTrackingConfiguration()
configuration.userFaceTrackingEnabled = true
backView.session.run(configuration)
// session for the front camera
guard ARFaceTrackingConfiguration.isSupported else { return }
let configurationFront = ARFaceTrackingConfiguration()
configurationFront.isLightEstimationEnabled = true
frontView.session.run(configurationFront, options: [])
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Pause the view's session
sceneView.session.pause()
}
func session(_ session: ARSession, didFailWithError error: Error) {
// Present an error message to the user
}
func sessionWasInterrupted(_ session: ARSession) {
// Inform the user that the session has been interrupted, for example, by presenting an overlay
}
func sessionInterruptionEnded(_ session: ARSession) {
// Reset tracking and/or remove existing anchors if consistent tracking is required
}
}
The back camera stops its video feed while the front camera is working properly. Any chances to solve this ?
It would also be a solution to run one ARSession and one low level video capture session on the other camera but i am running into the same problems.