我想检测面部并从中裁剪面部,但是当我使用imagePicker捕获图像时,检测到的面部特征数组会给出一个空数组。但是当我以前给出一个样本图像(jpg)时,已经检测到了脸部。
我检测脸部特征的代码
-(void)findFace:(UIImage*)image
{
NSDictionary *options = [NSDictionary dictionaryWithObject: CIDetectorAccuracyHigh forKey: CIDetectorAccuracy];
CIDetector *detector = [CIDetector detectorOfType: CIDetectorTypeFace context: nil options: options];
CIImage *ciImage = [CIImage imageWithCGImage: [image CGImage]];
NSNumber *orientation = [NSNumber numberWithInt:[image imageOrientation]+1];
NSDictionary *fOptions = [NSDictionary dictionaryWithObject:orientation forKey: CIDetectorImageOrientation];
// NSArray *features = [detector featuresInImage:ciImage options:fOptions];
NSArray* features = [detector featuresInImage:ciImage];
for (CIFaceFeature *f in features) {
NSLog(@"left eye found: %@", (f. hasLeftEyePosition ? @"YES" : @"NO"));
NSLog(@"right eye found: %@", (f. hasRightEyePosition ? @"YES" : @"NO"));
NSLog(@"mouth found: %@", (f. hasMouthPosition ? @"YES" : @"NO"));
if(f.hasLeftEyePosition)
NSLog(@"left eye position x = %f , y = %f", f.leftEyePosition.x, f.leftEyePosition.y);
if(f.hasRightEyePosition)
NSLog(@"right eye position x = %f , y = %f", f.rightEyePosition.x, f.rightEyePosition.y);
if(f.hasMouthPosition)
NSLog(@"mouth position x = %f , y = %f", f.mouthPosition.x, f.mouthPosition.y);
}
}
感谢任何帮助。