Google Vision crashes when getting UIImage from sample buffer

456 Views Asked by At

I finally decided to use Google Mobile Vision sdk for detecting faces and smiling in camera and their sdk and sample look very good and promising.

But after I pasted their sample code into my project it always crashes in captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) callback. Here is the code snap which always throws BAD_ACCESS exception.

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
    }
}

Possible duplicate Google Face Detection crashing when converting to image and trying to detect face but there's no correct answer to it.

Thanks in any advance.

1

There are 1 best solutions below

0
On

Finally ended up setting sessionPresset of AVCaptureSession to AVCaptureSessionPresetMedium.

    self.session.sessionPreset = .medium

Obviously there's a memory leak in the library.