gpt4 book ai didi

filter - 使用 GPUImage 框架在过滤器链之间切换

转载 作者:行者123 更新时间:2023-12-01 15:24:18 31 4
gpt4 key购买 nike

我想使用下面的代码在案例 1案例 2 中所示的两个过滤器链之间切换。当我最初选择这两种情况时,输出看起来都是正确的。然而,当我切换到另一个过滤器链时,输出在当前和先前的过滤器链之间闪烁。切换过滤器链的推荐方法是什么?

-(void) updateFilter:(NSInteger) style {
switch (style) {
case 1:
[kuwahara setRadius:5];
[videoCamera addTarget:kuwahara];
[kuwahara addTarget:grayscale];
[grayscale addTarget:filteredVideoView];
break;
case 2:
[videoCamera addTarget:grayscale];
[blur setBlurSize:3];
[grayscale addTarget:blur];
[blur addTarget:colorinvert];
[colorinvert addTarget:filteredVideoView];
break;
default:
[videoCamera addTarget:filteredVideoView];
break;
}
[videoCamera startCameraCapture];
}

最佳答案

根据您应用的情况,您可能还需要考虑 GPUImageFilterPipeline 类。

它将负责添加和删除 Brad 引用的所有干预目标。

如果这些过滤器的重复设置/拆卸对您来说是个问题,但在您的类(class)中将它们保存在内存中不是问题,那么您可能会喜欢管道。

根据您提供的大致内容,它可能看起来像这样:

- (void)configureSomeArraysOfFilters {
_setNumberOne = [[NSMutableArray alloc] init]; //make sure these arrays are at least scoped to the class, if not actual @properties
GPUImageKuwaharaFilter* kuwahara = [[GPUImageKuwaharaFilter alloc] init];
[kuwahara setRadius:5];
GPUImageGrayscaleFilter* gray = [[GPUImageGrayscaleFilter alloc] init];
[_setNumberOne addObject:kuwahara];
[_setNumberOne addObject:gray];


_setNumberTwo = [[NSMutableArray alloc] init];
GPUImageGrayscaleFilter* otherGray = [[GPUImageGrayscaleFilter alloc] init];
GPUImageGaussianBlurFilter* blur = [[GPUImageGaussianBlurFilter alloc] init];
[blur setBlurSize:3];
GPUImageColorInvertFilter* invert = [[GPUImageColorInvertFilter alloc] init];
[_setNumberTwo addObject:otherGray];
[_setNumberTwo addObject:blur];
[_setNumberTwo addObject:invert];
}

- (void)configureAnEmptyPipeline {
if (_samplePipeline == nil) {
GPUImageFilter* passthrough = [[GPUImageFilter alloc] init];
NSArray* empty = [NSArray arrayWithObjects:passthrough, nil];
_samplePipeline = [[GPUImageFilterPipeline alloc] initWithOrderedFilters:empty input:videoCamera output:_filteredVideoView];
[videoCamera startCameraCapture];
}
}

- (void)updateFilterPipeline:(NSInteger)style {
switch (style) {
case 1:
[_samplePipeline replaceAllFilters:_setNumberOne];
break;

case 2:
[_samplePipeline replaceAllFilters:_setNumberTwo];

//add as many more cases as you have defined Arrays full of filters for

default:
break;
}
}

然而,我最喜欢的管道用例是在运行时动态创建过滤器集,然后将它们切换为 Action 。它允许我简单地按顺序存储过滤器,然后将它们传递给管道,而不必每次都指定每个过滤器之间的所有目标。

它并不适用于所有情况,但 GPUImageFilterPipeline 在某些情况下可能非常有用。

关于filter - 使用 GPUImage 框架在过滤器链之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19254210/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com