如果我从横向模式单击快照,则人脸检测算法不起作用

时间:2012-07-23 07:04:40

标签: iphone ios ipad ios5 ios4

我使用以下代码从图像中检测到脸部:

-(void)markFaces:(UIImageView *)imagePick {

CIImage* image = [CIImage imageWithCGImage:imagePick.image.CGImage];
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace 
                                          context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
NSDictionary* imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:6] forKey:CIDetectorImageOrientation];
NSLog(@"imageOptions %@",imageOptions);
NSArray* features = [detector featuresInImage:image options:imageOptions];

if([features count] > 0)
{
    NSLog(@"Face Found");
}
else
{
    NSLog(@"Face not Found");        
}
}

如果我从横向模式单击快照,则此算法无效。为什么?任何帮助将不胜感激。

先谢谢

1 个答案:

答案 0 :(得分:0)

我认为问题出在这一行:

NSDictionary* imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:6] forKey:CIDetectorImageOrientation];

你实际上是在告诉它只寻找纵向,因为你传递的数字是6。

头文件中的文档说:

  

//可以使用的选项 - [CIDetector featuresInImage:options:]

     

/ *此键的值是1..8之间的整数NSNumber,例如    在kCGImagePropertyOrientation中找到。如果存在,将进行检测    基于该方向,但返回的要素中的坐标将    仍然是基于图像的那些。 * /

选项是

enter image description here

令人讨厌featuresInImage:options:没有记录(我现在必须提交一个bug,我已经看过了)