如何正确实例iOS 5中的人脸检测API CIDetector类对象 [英] How to properly instantiate CIDetector class object in iOS 5 face detection API

查看:133
本文介绍了如何正确实例iOS 5中的人脸检测API CIDetector类对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读苹果的文档我试图使用它的新的人脸检测的API,但没有运气,,尽管没有编译或运行时错误的实例方法 featuresInImage 始终返回CIFeature的对象数组与空值。

reading the Apple's documentation i tried using it's new face detection API but with no luck,, although there are no compile or runtime errors the instance method featuresInImage always return an array of CIFeature objects with null values.

第一个计时器上的计算器,还是尽我所能短而具体。

First timer on stackoverflow, still tried my best to be short and specific.

推荐答案

一个最小的code(工作),以测试新的iOS 5人脸检测API

A minimal code (working) to test out the new iOS 5 face detection API

- (void)viewDidLoad{

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

CIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"IMG_0056.JPG"]];

NSLog(@"showing image now");
//[imageView setImage:image];


if (ciImage == nil)
    NSLog(@"CIImage is nil");


//imageView.image = [UIImage imageWithCGImage:[context createCGImage:ciImage fromRect:ciImage.extent]];
[imageView setImage:[UIImage imageNamed:@"IMG_0056.JPG"]];

NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                         @"CIDetectorAccuracy", @"CIDetectorAccuracyHigh",nil];
CIDetector *ciDetector = [CIDetector detectorOfType:CIDetectorTypeFace 
                                            context:nil
                                            options:options];
NSArray *features = [ciDetector featuresInImage:ciImage];
NSLog(@"no of face detected: %d", [features count]);
NSString *myString = [[NSString alloc] initWithFormat:@"%d face(s) detected\n",[features count]];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Face detection" message:myString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];

}

这篇关于如何正确实例iOS 5中的人脸检测API CIDetector类对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆