1

我是 iOS 编程新手,我搜索了很多核心图片链接、答案和教程,但我仍然不完全理解。我有一个测试应用程序,它有按钮,简单的东西,当我按下某个过滤器按钮时,我有图像,它会生成过滤器并显示它。

CIImage *inputImage = [[CIImage alloc]initWithImage:[UIImage imageNamed:@"pic1.JPG"]];
    CIFilter *colorControls = [CIFilter filterWithName:@"CIColorControls"];
    [colorControls setValue:inputImage forKey:@"inputImage"];
    [colorControls setValue:[NSNumber numberWithFloat:0.5f] forKey:@"inputSaturation"];
    [colorControls setValue:[NSNumber numberWithFloat:0.8f] forKey:@"inputContrast"];
    [colorControls setValue:[NSNumber numberWithFloat:0.4f] forKey:@"inputBrightness"];
    CIImage *outputImage = [colorControls valueForKey:@"outputImage"];
    CIContext *context = [CIContext contextWithOptions:nil];
    theImageView.image = [UIImage imageWithCGImage:[context createCGImage:outputImage fromRect:outputImage.extent]];

现在我想要一个按钮,它可以检测眼睛和嘴巴并在其周围绘制矩形或圆圈,无论什么颜色和什么颜色都没有关系。我来了,直到

- (IBAction)detectFace:(id)sender
{
    CIImage *inputImage = [[CIImage alloc]initWithImage:[UIImage imageNamed:@"pic1.JPG"]];
    CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
                                              context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
    NSArray* features = [detector featuresInImage:inputImage];
   for (CIFaceFeature *faceFeature in features){}
}

现在我有一个问题(我不确定这是否是正确的开始)。请帮助我想知道下一步该怎么做..提前谢谢你

4

1 回答 1

1

怎么样(还没有编译它,但应该很接近):

for (CIFaceFeature *faceFeature in features){
        CGRect faceRect = faceFeature.bounds;

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 1.0);

    CGContextAddRect(context, faceRect);
    CGContextDrawPath(context, kCGPathStroke);
}
于 2013-03-26T13:52:22.607 回答