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

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

问题描述

阅读 Apple 的文档,我尝试使用它的新人脸检测 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.

stackoverflow 上的第一次尝试,我仍然尽力简短而具体.

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

推荐答案

测试新的 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天全站免登陆