0

我最终决定使用 Google Mobile Vision sdk 来检测人脸并在相机中微笑,他们的 sdk 和示例看起来非常好而且很有前途。

但是在我将他们的示例代码粘贴到我的项目中之后,它总是在captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)回调中崩溃。这是总是抛出 BAD_ACCESS 异常的代码快照。

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
    if (faceDetector == nil) {
        self.faceDetector = GMVDetector(ofType: GMVDetectorTypeFace, options: [GMVDetectorFaceLandmarkType: GMVDetectorFaceLandmark.all.rawValue,
                                                                               GMVDetectorFaceClassificationType: GMVDetectorFaceClassification.all.rawValue,
                                                                               GMVDetectorFaceMinSize: 0.3,
                                                                               GMVDetectorFaceTrackingEnabled: true])
    }
    guard let image = GMVUtility.sampleBufferTo32RGBA(sampleBuffer) else { // <-- this is where throws exception
        print("Invalid sample buffer")
        return
    }
}

转换为图像并尝试检测人脸时可能会出现重复的 Google 人脸检测崩溃,但没有正确答案。

提前感谢。

4

1 回答 1

0

最后将 AVCaptureSession 的 sessionPresset 设置为 AVCaptureSessionPresetMedium。

    self.session.sessionPreset = .medium

显然库中存在内存泄漏。

于 2017-11-14T17:54:56.917 回答