最近開發(fā)的app中有個實名認(rèn)證的環(huán)節(jié)喇喉,需要上傳一張自拍照孤钦,為了檢測用
戶上傳審核的是人臉照片而非其他的東西择葡,就用到了系統(tǒng)自帶的檢測人臉的方
法,廢話不多說直接上代碼:
- (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;
}
檢測到人臉.png