CIDetector不工作

时间:2014-03-16 05:11:09

标签: ios objective-c core-image

我运行了以下代码并且它在行上反复崩溃:“NSDictionary * orientation = [NSDictionary dictionaryWithObjectsAndKeys ...”有没有人知道为什么?

-(void)scanFace{
    UIImageOrientation imgOrientation = imgView.image.imageOrientation;
    NSNumber *numOrient = [NSNumber numberWithInt:imgOrientation];
    NSDictionary *orientation = [NSDictionary dictionaryWithObjectsAndKeys:numOrient, CIDetectorImageOrientation, [NSNumber numberWithBool:YES], CIDetectorEyeBlink, nil];

    CIImage *newImage = [CIImage imageWithCGImage:imgView.image.CGImage options:orientation];

    CIContext *context = [CIContext contextWithOptions:nil];
    CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace context:context options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];

    NSArray *features = [detector featuresInImage:newImage options:orientation];

    if (features.count == 0) {
        NSLog(@"NO FACE %i", features.count);
    } else {
        NSLog(@"FACE FOUND %i", features.count);
    }

    for (CIFaceFeature *feature in features) {

        if (feature.leftEyeClosed == YES) {
            leftLab.text = [NSMutableString stringWithFormat:@"Left Eye Closed"];
        } else {
            leftLab.text = [NSMutableString stringWithFormat:@"Left Eye Open"];
        }
        if (feature.rightEyeClosed == YES) {
            rightLab.text = [NSMutableString stringWithFormat:@"Right Eye Closed"];
        } else {
            rightLab.text = [NSMutableString stringWithFormat:@"Right Eye Open"];
        }

    }
}    

0 个答案:

没有答案