红眼校正

时间:2016-07-28 14:20:48

标签: objective-c filter face-detection

要添加红眼校正效果,我已按照以下链接:

How to remove red eye from image in iPhone?

通过pod安装在库上方。在我的课程中添加了以下代码。

UIImage *redEyeImage = [UIImage imageNamed:@"Userimage"];

if (redEyeImage) {
    UIImage *newRemovedRedEyeImage = [redEyeImage redEyeCorrection];
    if (newRemovedRedEyeImage) {
        imgView.image = newRemovedRedEyeImage;
    }
}

但我没有得到所需的输出。有什么我想念的吗?或者是否有其他库来实现这个概念。请建议。

谢谢!

2 个答案:

答案 0 :(得分:0)

您可以在两个if语句后面的行上设置断点,然后运行您的应用并查看它们是否被点击(可能redEyeImage不存在或newRemovedRedEyeImage没有。< / p>

另一种简单的检查方法是:

UIImage *redEyeImage;
UIImage *newRemovedRedEyeImage;

redEyeImage = [UIImage imageNamed:@"Userimage"];

if (redEyeImage) {
    newRemovedRedEyeImage = [redEyeImage redEyeCorrection];
    if (newRemovedRedEyeImage) {
        imgView.image = newRemovedRedEyeImage;
    }
}

NSLog(@"redEyeImage: %@", (redEyeImage != nil ? @"exists" : @"nil"));
NSLog(@"newRemovedRedEyeImage: %@", (newRemovedRedEyeImage != nil ? @"exists" : @"nil"));

然后运行它,看看底部打印的两个日志。

答案 1 :(得分:0)

最后,我使用以下代码解决了这个问题:

UIImage *img = [UIImage imageNamed:@"images.png"];
CIImage *image = [[CIImage alloc]initWithImage:img];
NSLog(@"after ciimage: %@", kCIImageAutoAdjustEnhance);
NSDictionary *options = [NSDictionary dictionaryWithObject:@"NO" forKey:kCIImageAutoAdjustEnhance];
NSLog(@"options: %@", options);
NSArray *adjustments = [image autoAdjustmentFiltersWithOptions:options];
NSLog(@"adjustments: %@  ", adjustments);

for (CIFilter * filter in adjustments)
{
    [filter setValue:image forKey:kCIInputImageKey];
    image = filter.outputImage;
}
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgImage = [context createCGImage:image fromRect:image.extent];
UIImage *enhancedImage = [[UIImage alloc] initWithCGImage:cgImage];
CGImageRelease(cgImage);
self.img.image = enhancedImage;