开始使用前置摄像头玩MLKit面部检测器,但是在处理面部时确实很慢
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
print("Picture at ", Date())
let visionImage = VisionImage(buffer: sampleBuffer)
visionImage.metadata = metadata
faceDetector?.detect(in: visionImage) { (faces, error) in
guard error == nil, let faces = faces, !faces.isEmpty else {
// Error. You should also check the console for error messages.
let errorString = error?.localizedDescription
print("Face detection failed with error: \(errorString)")
return
}
}
Run Code Online (Sandbox Code Playgroud)
我要去哪里错了?