【问题标题】:How to use GPUImageMaskFilter with camera input如何将 GPUImageMaskFilter 与相机输入一起使用
【发布时间】:2014-07-29 05:01:38
【问题描述】:

我正在使用 BradLarson 的 GPUImage iOS 框架。我正在尝试按照 filtershowcase 中的示例为我的实时摄像机输入添加一个遮罩。对于其他过滤器,这个简单的链可以工作,但对于 GPUImageMaskFilter 则不能。我的输出只是一个白屏。缺少什么?

这是我的代码:

    stillCamera = [[GPUImageStillCamera alloc] init];
    stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

    GPUImageView *filterView = [[GPUImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 427)];
    [self.view addSubview:filterView];

    maskFilter = [[GPUImageMaskFilter alloc] init];
    [(GPUImageFilter*)maskFilter setBackgroundColorRed:0.0 green:1.0 blue:0.0 alpha:1.0];
    UIImage *mask = [UIImage imageNamed:@"mask.png"];
    GPUImagePicture *maskImage = [[GPUImagePicture alloc] initWithImage:mask smoothlyScaleOutput:YES];
    [maskImage processImage];
    [maskImage addTarget:maskFilter];

    [stillCamera addTarget:maskFilter];
    [maskFilter addTarget:filterView];

    [stillCamera startCameraCapture];

我也尝试过使用 GPUImageVideoCamera,但这并没有帮助。我认为问题可能出在过滤器链或掩码过滤器的声明上。

我检查了这个问题How to Implement GPUImageMaskFilter using GPUImage,但这是针对静态图片而不是实时相机输入。

有什么想法吗?

【问题讨论】:

    标签: ios mask gpuimage gpuimagestillcamera


    【解决方案1】:

    您需要先添加以下目标:

    [stillCamera addTarget:maskFilter];
    [maskImage addTarget:maskFilter];
    

    然后处理图像:

    [maskImage processImage];
    

    然后您可以将过滤结果传递给视图:

    [maskFilter addTarget:filterView];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 2018-08-30
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多