CIFaceFeature仅适用于LandscapeLeft

时间:2012-06-19 22:14:19

标签: iphone ios orientation face-detection

关于如何进行人脸检测的a tutorial from iTunes U(教程仅在视频中,而不是在线编写,因此我无法发布直接链接)。基本上,我已经让脸部检测工作,但只有当手机处于LandscapeLeft模式时。

关于它为何如此运作的任何想法?

1 个答案:

答案 0 :(得分:4)

没有看到你的代码就很难说,但我的猜测是你没有设置CIDetectorImageOrientation?当图像方向与探测器方向设置不匹配时,我检测失败。

下面的一些代码 - 不是剪切'粘贴,而是更多粗略的例子。

- (void)detectFacialFeatures:(UIImage *)image withHighAccuracy:(BOOL) highAccuracy
{

CIImage* ciImage = [CIImage imageWithCGImage:sourceImage.CGImage];

if (ciImage == nil){
    printf("ugh \n");
    // bail
}

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    NSString *accuracy = highAccuracy ? CIDetectorAccuracyHigh : CIDetectorAccuracyLow;

    NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
                             CIDetectorAccuracyHigh, CIDetectorAccuracy,
                             orientation, CIDetectorImageOrientation,
                             nil];

    CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace 
                                              context:nil options:options];

    NSArray *features = [detector featuresInImage:ciImage];

    NSLog(@"features %@", features);

});
}