【问题标题】:How to properly instantiate CIDetector class object in iOS 5 face detection API如何在 iOS 5 人脸检测 API 中正确实例化 CIDetector 类对象
【发布时间】:2013-05-21 13:05:45
【问题描述】:

阅读了 Apple 的文档,我尝试使用它的新人脸检测 API,但没有运气,尽管没有编译或运行时错误,但实例方法 featuresInImage 总是返回一个具有空值的 CIFeature 对象数组。

stackoverflow 上的第一个计时器,仍然尽力做到简短而具体。

【问题讨论】:

  • 在此处发布后从其他来源获得了正确的方法 :-),代码运行良好,我认为我应该分享它或者回答我自己的问题 :-)

标签: api ios5


【解决方案1】:

测试新 iOS 5 人脸检测 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];

}

【讨论】:

    【解决方案2】:
    UIImage* uiimage = nil;
    CIImage* image = [CIImage imageWithCGImage:uiimage.CGImage];
    CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
    

    完整教程见这里 http://b2cloud.com.au/how-to-guides/face-detection-in-ios-5

    【讨论】:

      猜你喜欢
      • 2015-03-14
      • 2013-05-02
      • 2012-06-24
      • 2015-12-23
      • 1970-01-01
      • 2019-03-05
      • 2012-08-27
      • 2017-09-04
      • 2013-07-03
      相关资源
      最近更新 更多