Hello everybody, I am new in DeepAR. I wrote this simple code where I am trying to print the value of some landmarks and I am using the MVVM design. Could anybody help me understanding why once the model.deepAR.delegate = self line is run (I get the print on the terminal) the faceTracked function is never called (I can’t see the print on terminal) when I run the app and my face is clearly visible?
import SwiftUI
import DeepAR
struct ContentView: View {
@ObservedObject var arViewModel = DeepARViewModel()
var body: some View {
DeepARViewContainer(arViewModel: arViewModel)
.edgesIgnoringSafeArea(.all)
}
}
struct DeepARViewContainer: UIViewRepresentable {
var arViewModel: DeepARViewModel
func makeUIView(context: Context) -> UIView {
arViewModel.startSessionDelegate()
return arViewModel.arView
}
func updateUIView(_ uiView: UIView, context: Context) {
// Update the view if needed
}
}
struct DeepARModel {
// Your DeepAR logic here
var deepAR: DeepAR!
private var cameraController: CameraController!
var arView: UIView!
var lefMouthLandmark: Float = 0
var rightMouthLandmark: Float = 0
init() {
// Initialize and configure DeepARView
deepAR = DeepAR()
deepAR.setLicenseKey("my_key")
cameraController = CameraController()
cameraController.deepAR = deepAR
arView = deepAR.createARView(withFrame: UIScreen.main.bounds)
cameraController.startCamera()
}
mutating func update(multiFaceData: MultiFaceData) -> Void {
self.lefMouthLandmark = Float(multiFaceData.faceData.1.landmarks.55)
self.rightMouthLandmark = Float(multiFaceData.faceData.1.landmarks.49)
print(self.lefMouthLandmark)
print(self.rightMouthLandmark)
}
}
class DeepARViewModel: UIViewController, ObservableObject {
@Published private var model : DeepARModel = DeepARModel()
var arView : UIView {
model.arView
}
func startSessionDelegate() {
print("Session delegate on")
model.deepAR.delegate = self
}
}
extension DeepARViewModel: DeepARDelegate {
func faceTracked(_ faceData: MultiFaceData) {
print("In the face Tracked")
model.update(multiFaceData: faceData)
}
}