2

I have built an app that uses image tracking and swaps flat images. I am also using people occlusion (now) so people can get photos in front of those images. I really want this app to have a selfie mode, so people can take their own pictures in front of image swapped areas.

I'm reading the features on ARKit 3.5, but as far as I can tell, the only front-facing camera support is with ARFaceTrackingConfiguration, which doesn't support image tracking. ARImageTrackingConfiguration and ARWorldTrackingConfiguration only use the back camera.

Is there any way to make a selfie mode with people occlusion (and image tracking) using the front-facing camera?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Jeffrey Berthiaume
  • 4,054
  • 3
  • 35
  • 45

1 Answers1

6

The answer is NO, you can't use any ARConfiguration except ARFaceTrackingConfiguration for front camera. Although, you can simultaneously use ARFaceTrackingConfiguration on the front camera and ARWorldTrackingConfiguration on the rear camera. This allows users interact with AR content in the rear camera using their face as certain controller.

Look at this docs page to find out what config to what camera (rear or front) corresponds to.

Here's a table containing ARKit 5.0 eight tracking configurations:

ARConfiguration What Camera?
ARWorldTrackingConfiguration Rear
ARBodyTrackingConfiguration Rear
AROrientationTrackingConfiguration Rear
ARImageTrackingConfiguration Rear
ARFaceTrackingConfiguration FRONT
ARObjectScanningConfiguration Rear
ARPositionalTrackingConfiguration Rear
ARGeoTrackingConfiguration Rear

Simultaneous World and Face configs

To use driven World Tracking depending on driver Face Tracking use the following code:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    
    guard ARFaceTrackingConfiguration.isSupported,
          ARFaceTrackingConfiguration.supportsWorldTracking
    else {
        fatalError("We can't do face tracking")
    }        
    let config = ARFaceTrackingConfiguration()
    config.isWorldTrackingEnabled = true
    sceneView.session.run(config)
}

Or you can use Face Tracking as a secondary configuration:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    
    let config = ARWorldTrackingConfiguration()
    
    if ARFaceTrackingConfiguration.isSupported {
        config.userFaceTrackingEnabled = true
    }
    sceneView.session.run(config)
}

Pay attention that both properties are available on iOS 13 and higher.

var userFaceTrackingEnabled: Bool { get set }

var isWorldTrackingEnabled: Bool { get set }

P.S.

At the moment .userFaceTrackingEnabled = true still doesn't work. I tested it in Xcode 13.2.1 and iPad Pro 4th Gen with iPadOS 15.3 installed.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • 1
    How to simultaneously use ARFaceTrackingConfiguration on the front and ARWorldTrackingConfiguration on the rear camera? Can you please post a sample for that? – Vidhya Sri Aug 11 '21 at 05:56
  • Thank you! Also, does iPad Pro-2020 support this simultaneous usage of front and back cameras? Do all ARKit supported devices support this feature? – Vidhya Sri Aug 11 '21 at 07:48
  • 100%, if device has a TrueDepth sensor. But I haven't tried devices without TrueDepth. – Andy Jazz Aug 11 '21 at 07:51
  • And simultaneous config works on iOS 13 and higher. – Andy Jazz Aug 11 '21 at 08:03
  • I am getting a strange issue. When I have Face tracking configuration as primary and World tracking configuration as Secondary, it works. But when I have world tracking configuration as primary and face tracking as secondary, it says "Unsupported AR Configuration". I am trying this in iPad Pro 4th gen model. Is there anything i am missing here? – Vidhya Sri Aug 11 '21 at 08:22
  • What's your iOS version? – Andy Jazz Aug 11 '21 at 08:25
  • 1
    iOS version is 14.6. – Vidhya Sri Aug 11 '21 at 08:26
  • That's wierd but iPhone X (with iOS 14.7.1) catches the same error. I'll try it later on iPad Pro Gen 4. – Andy Jazz Aug 11 '21 at 08:58
  • 1
    @yaali you're right. `userFaceTrackingEnabled` instance property doesn't work on iPad Pro Gen 4 as well. Very strange issue((((. I hope Apple will fix it. – Andy Jazz Aug 11 '21 at 15:03