慢速面部检测Firebase MLKit [英] Slow face detection Firebase MLKit

查看:117
本文介绍了慢速面部检测Firebase MLKit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始使用前置摄像头玩MLKit人脸检测器,但是处理人脸的速度确实很慢

Started playing around with MLKit face detectors with the front-facing camera, but it's really slow on processing faces

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
        }

  }

我要去哪里了?

推荐答案

有一些方法可以尝试加快检测速度:

There are a few things you can try to speed up the detection:


  1. 构建

  1. Build your app in the release mode (optimized), as opposed to the debug mode.

在创建FaceDetector时,请确保使用VisionFaceDetectorOptions并设置其isTrackingEnabled为true。

When creating your faceDetector, please make sure to use a VisionFaceDetectorOptions and set its isTrackingEnabled to true.

设置AVCaptureVideoDataOutput时,请将以下键值对添加到其videoSettings中:

When setting up your AVCaptureVideoDataOutput, please add the following key-value pair to its videoSettings:

键:kCVPixelBufferPixelFormatTypeKey

key: kCVPixelBufferPixelFormatTypeKey

值:kCVPixelFormatType_32BGRA

value: kCVPixelFormatType_32BGRA

这篇关于慢速面部检测Firebase MLKit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆