0

我已使用以下代码检测 IOS 5 的面部

CIImage  *cIImage = [CIImage imageWithCGImage:image.CGImage];
            CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
            NSArray *features = nil;
            features = [detector featuresInImage:cIImage];
            if ([features count] == 0) 
            {
                NSDictionary* imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:6] forKey:CIDetectorImageOrientation];
                features = [detector featuresInImage:cIImage options:imageOptions];
            }

使用此代码,我可以在 IOS 5 中检测到人脸,但最近我们已将系统升级到 Xcode 4.4 和 IOS 6,现在,人脸检测无法正常工作,

在 IOS 6 中检测人脸需要做哪些更改。

任何帮助都受到高度赞赏

4

2 回答 2

1

我注意到 iOS6 中的人脸检测不如 iOS5 中的好。尝试选择图像。你可能会发现它在 iOS6 中可以正常工作,有很多图像,但不是全部。

我一直在测试同一组图像: 1. 运行 iOS6 的模拟器。2. iPhone 5 (iOS6) 3. iPhone 3GS (iOS5)。

3GS 检测到的人脸比其他两个选项多。

这是代码,它适用于两者,但在 iOS6 上效果不佳:

- (void)analyseFaces:(UIImage *)facePicture {
// Create CI image of the face picture
CIImage* image = [CIImage imageWithCGImage:facePicture.CGImage];

// Create face detector with high accuracy
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
                                          context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];

// Create array of detected faces
NSArray* features = [detector featuresInImage:image];

// Read through the faces and add each face image to facesFound mutable
for(CIFaceFeature* faceFeature in features)
{
    CGSize parentSize = facePicture.size;

    CGRect origRect = faceFeature.bounds;
    CGRect flipRect = origRect;
    flipRect.origin.y = parentSize.height - (origRect.origin.y + origRect.size.height);

    CGImageRef imageRef = CGImageCreateWithImageInRect([facePicture CGImage], flipRect);
    UIImage *faceImage = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);

    if (faceImage)
        [facesFound addObject:faceImage];
} 

}

于 2012-10-19T05:05:37.693 回答
0

我希望这对你有帮助...

添加CoreImage.framework

-(void)faceDetector

{

// Load the picture for face detection

UIImageView* image = [[UIImageView alloc] initWithImage:

[UIImage imageNamed:@"facedetectionpic.jpg"]];

// Draw the face detection image

[self.window addSubview:image];

// Execute the method used to markFaces in background

[self markFaces:image];

}


-(void)faceDetector

{

// Load the picture for face detection

    UIImageView* image = [[UIImageView alloc] initWithImage:[UIImage 
imageNamed:@"facedetectionpic.jpg"]];


    // Draw the face detection image
    [self.window addSubview:image];

    // Execute the method used to markFaces in background
    [self performSelectorInBackground:@selector(markFaces:) withObject:image];

    // flip image on y-axis to match coordinate system used by core image
    [image setTransform:CGAffineTransformMakeScale(1, -1)];

    // flip the entire window to make everything right side up
    [self.window setTransform:CGAffineTransformMakeScale(1, -1)];


}

并检查这两个链接

http://maniacdev.com/2011/11/tutorial-easy-face-detection-with-core-image-in-ios-5/

http://i.ndigo.com.br/2012/01/ios-facial-recognition/

于 2012-10-05T13:50:32.030 回答