开始使用带有前置摄像头的 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
}
}
我哪里错了?