来自UIImagePickerViewController的人脸检测

时间:2012-12-31 02:22:51

标签: iphone objective-c xcode uiimagepickercontroller face-detection

***** EDIT ******

我正在做一些测试,看看我是否遗漏了一些东西,结果发现imgHolder.image正在返回null,但它正在显示一个图像。我在[void viewDidLoad]上调用它。

***** EDIT ******

我正在创建一个您拍摄照片的简单应用程序,然后将该图像传递给另一个视图控制器并尝试在图像中检测您的脸部。我已经尝试过使用很多教程,然后使用Google搜索问题,但我找不到解决方案。问题是,无论我多少次更改代码或尝试其他图片,它都不会检测到任何功能。我尝试过的一些教程和我的代码一起列在下面。

CIImage* image = [CIImage imageWithCGImage:imgHolder.image.CGImage];
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
NSDictionary *imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:6]
                                                         forKey:CIDetectorImageOrientation];
NSArray* features = [detector featuresInImage:image options:imageOptions];
for(CIFaceFeature* feature in features)
{
    UIView* face = [[UIView alloc] initWithFrame:feature.bounds];
    [face setBackgroundColor:[[UIColor yellowColor] colorWithAlphaComponent:0.4]];
    [self.view.window addSubview:face];

    if(feature.hasLeftEyePosition)
    {
        UIView* eye = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
        [eye setBackgroundColor:[[UIColor blueColor] colorWithAlphaComponent:0.2]];
        [eye setCenter:feature.leftEyePosition];
        [self.view.window addSubview:eye];
    }

    if(feature.hasRightEyePosition)
    {
        UIView* eye = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
        [eye setBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.2]];
        [eye setCenter:feature.rightEyePosition];
        [self.view.window addSubview:eye];
    }

    if(feature.hasMouthPosition)
    {
        UIView* mouth = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
        [mouth setBackgroundColor:[[UIColor greenColor] colorWithAlphaComponent:0.2]];
        [mouth setCenter:feature.mouthPosition];
        [self.view.window addSubview:mouth];
    }
}
NSLog(@"%d", features.count);

http://www.tokbox.com/blog/fun-with-core-graphics-in-ios/ http://b2cloud.com.au/how-to-guides/face-detection-in-ios-5 CIDetector and UIImagePickerController

0 个答案:

没有答案
相关问题