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.