【问题标题】:GPUImage GPUImageChromaKeyBlendFilter With Still ImageGPUImage GPUImageChromaKeyBlendFilter 与静止图像
【发布时间】:2013-09-01 11:05:03
【问题描述】:

我想创建一个 GPUImageView 来实时显示过滤器(而不是一直读取 imageFromCurrentlyProcessedOutput)

是否可以将 GPUImage 的 GPUImageChromaKeyBlendFilter 与自动更新 GPUImageView 的静止源图像一起使用?

这是我将其读入 UIImage 的代码;

    UIImage *inputImage = [UIImage imageNamed:@"1.JPG"];
    UIImage *backgroundImage = [UIImage imageNamed:@"2.JPG"];

    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
    GPUImageChromaKeyBlendFilter *stillImageFilter = [[GPUImageChromaKeyBlendFilter alloc] init];
    [stillImageFilter setThresholdSensitivity:0.5];
    [stillImageFilter setColorToReplaceRed:0.0 green:1.0 blue:0.0];


    [stillImageSource addTarget:stillImageFilter];
    [stillImageSource processImage];


    UIImage *currentFilteredVideoFrame = [stillImageFilter imageByFilteringImage: backgroundImage ];

到目前为止,我所做的一切都要求您将“backgroundImage”作为目标添加到过滤器(就像您使用 StillCamera 时一样)。如果您将 backgroundImage 添加为目标,GPUImage 只会将此新图像用作其基础图像。

谁能帮忙?

谢谢,

【问题讨论】:

  • 你能告诉我你的解决方案吗?
  • 您介意分享您的解决方案吗?

标签: ios filtering gpuimage


【解决方案1】:

不要将-imageByFilteringImage: 与双输入过滤器一起使用,例如混合。这是一种方便的方法,可以快速建立一个基于 UIImage 的小过滤器链并抓取一个 UIImage。无论如何,你不会想要它用于针对 GPUImageView 的东西。

对于色度键混合,您需要使用-addTarget 将输入图像(具有要替换颜色的图像)和背景图像定位到混合,并使用 GPUImagePicture 实例。然后,您将混合目标定位到 GPUImageView。

请注意,如果您想在此之后继续更新过滤器,则需要在 setup 方法之后保持对 GPUImagePictures 的强引用,因此您可能需要在控制器类上将它们设为实例变量。

一旦您以这种方式进行设置,结果将转到您的 GPUImageView。每次您在两个图像之一上调用-processImage 时,GPUImageView 中的显示都会更新。因此,您可以在每次更改过滤器设置后调用它,例如您有一个滑块来更新过滤器值,并且图像将实时更新。

【讨论】:

  • 完美。我一定在其他几个人中试过这个,但错过了滑块上的“-processImage”。谢谢布拉德 - 非常感谢。
  • 您好,您能告诉我如何从我拥有的 UIImage 中删除绿色吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多