最近开发的app中有个实名认证的环节,需要上传一张自拍照,为了检测用
户上传审核的是人脸照片而非其他的东西,就用到了系统自带的检测人脸的方
法,废话不多说直接上代码:
- (BOOL)detectionOfFaceWithImage:(UIImage *)image {
NSDictionary *imageOptions = [NSDictionary dictionaryWithObject:@(5) forKey:CIDetectorImageOrientation];
CIImage *personciImage = [CIImage imageWithCGImage:image.CGImage];
NSDictionary *opts = [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy];
CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:opts];
NSArray *features = [faceDetector featuresInImage:personciImage options:imageOptions];
if (features.count > 0) return YES; else return NO;
}

网友评论