1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| #pragma mark - 检测人脸照片 - (UIImage *)getFaceImageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer{ CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CIImage *ciImage = [CIImage imageWithCVPixelBuffer:imageBuffer]; CIContext *temporaryContext = [CIContext contextWithOptions:nil]; CGImageRef videoImage; if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) { videoImage = [temporaryContext createCGImage:ciImage fromRect:CGRectMake(0, 80, 480, 480)]; }else{ videoImage = [temporaryContext createCGImage:ciImage fromRect:CGRectMake(80, 0, 480, 480)]; } UIImage *resultImg = [[UIImage alloc] initWithCGImage:videoImage]; CGImageRelease(videoImage); CIImage *resultCmg = [[CIImage alloc] initWithCGImage:resultImg.CGImage]; CIFaceFeature * faceFeature = [self.detector featuresInImage:resultCmg].linq_firstOrNil; if (faceFeature && faceFeature.hasLeftEyePosition && faceFeature.hasRightEyePosition && faceFeature.hasMouthPosition) { return resultImg; } return nil; }
|