【问题标题】:Google Vision crashes when getting UIImage from sample buffer从示例缓冲区获取 UIImage 时,Google Vision 崩溃
【发布时间】:2023-04-03 19:54:01
【问题描述】:

我最终决定使用 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 Face Detection crashing when converting to image and trying to detect face 可能重复,但没有正确答案。

提前致谢。

【问题讨论】:

    标签: swift uiimage google-vision android-vision google-ios-vision


    【解决方案1】:

    终于把 AVCaptureSession 的 sessionPresset 设置为 AVCaptureSessionPresetMedium。

        self.session.sessionPreset = .medium
    

    显然库中存在内存泄漏。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      • 2012-02-16
      • 2018-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多