0

我想检测面部并从中裁剪面部,但是当我使用 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);

    }
}

任何帮助表示赞赏。

4

0 回答 0