Hi @toojuice,
Glad to see your message! I didn’t receive a notification of your reply so I wasn’t able to answer you earlier.
I have been working on this issue in the last couple of days. I haven’t solved the issue, but I want to share what I have found out.
Before sharing my discoveries, I want to answer your question. I see the delay in the face landmarks, not so much in the boundingBox showing the detected face if that’s what you mean. When I move my head, the face landmarks are not catching up with my face movement. Here’s a video clip I recorded. You can see that it takes a second for the face landmarks to move to the right position on my face. When I use Snapchat filters, the bear ears and fake glasses added to my face can follow immediately when my face moves. Here’s a video clip showing how the bear ears and glasses staying at their correct position on my face all the time. I am using iPhone 6s.
I think the delay is because of the amount of time it takes to run the sequenceHandler analyzing the sampleBuffer. The time it takes to run the sequenceHandler is on average 0.1 second, during which time about 2-3 sampleBuffer were dropped.
Here is the code I used to get the time-elapse measured and count the amount of sampleBuffer dropped.
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
return
}
let detectFaceRequest = VNDetectFaceLandmarksRequest(completionHandler: detectedFace)
do {
// get the start time of the sequenceHandler
let start = Date()
// run the sequenceHandler
try sequenceHandler.perform(
[detectFaceRequest],
on: imageBuffer,
orientation: .leftMirrored)
// get the end time of the sequenceHandler, and calculate the time elapsed.
let end = Date()
print("A frame is analyzed, with elapse time : \(end.timeIntervalSince(start))")
} catch {
print(error.localizedDescription)
}
}
func captureOutput(_ output: AVCaptureOutput, didDrop sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
print("a frame is dropped!")
}
When I run the code above, I get the following results:
A frame is analyzed, with elapsed time : 0.099357008934021
a frame is dropped!
a frame is dropped!
A-frame is analyzed, with elapsed time : 0.08487498760223389
a frame is dropped!
a frame is dropped!
A frame is analyzed, with elapsed time : 0.08759593963623047
a frame is dropped!
a frame is dropped!
A frame is analyzed, with elapsed time : 0.08887004852294922
a frame is dropped!
A frame is analyzed, with elapsed time : 0.0864570140838623
a frame is dropped!
a frame is dropped!
A frame is analyzed, with elapsed time : 0.09023606777191162
a frame is dropped!
a frame is dropped!
A frame is analyzed, with elapsed time : 0.10215997695922852
a frame is dropped!
a frame is dropped!
A frame is analyzed, with elapsed time : 0.09466695785522461
a frame is dropped!
a frame is dropped!
A frame is analyzed, with elapsed time : 0.08662497997283936
a frame is dropped!
A frame is analyzed, with elapsed time : 0.09468793869018555
a frame is dropped!
a frame is dropped!
A frame is analyzed, with elapsed time : 0.10828900337219238
a frame is dropped!
a frame is dropped!
A frame is analyzed, with elapsed time : 0.12512493133544922
a frame is dropped!
a frame is dropped!
a frame is dropped!
A frame is analyzed, with elapsed time : 0.11516201496124268
a frame is dropped!
a frame is dropped!
a frame is dropped!
A frame is analyzed, with elapsed time : 0.11460399627685547
a frame is dropped!
a frame is dropped!
A frame is analyzed, with elapsed time : 0.11211204528808594
a frame is dropped!
a frame is dropped!
a frame is dropped!
The time it takes to run the updateFaceView is 0.004 second, which is very short.
I currently don’t know what to do next to solve this problem, I’ll be happy to try anything you might suggest!
Best regards,