问题
I have a problem with understanding GPUImage. Specifically, I can't figure out how to use GPUImageLookupFilter. I have several examples of usage in GPUImageAmatorkaFilter for example. But LookupFilter used there within GPUImageFilterGroup which I didn't understood yet either. I wonder whether I can use LookupFilter alone.
I've tried this:
GPUImageLookupFilter *lookup = [[GPUImageLookupFilter alloc] init];
UIImage *image = [UIImage imageNamed:@"amatorka.png"];
GPUImagePicture *lookupImageSource = [[GPUImagePicture alloc] initWithImage:image];
[lookupImageSource addTarget: lookup atTextureLocation: 1];
[lookupImageSource processImage];
GPUImagePicture *inputImg = [[GPUImagePicture alloc] initWithImage:inputImage];
[inputImg addTarget:lookup atTextureLocation: 1];
[inputImg processImage];
UIImage *quickFilteredImage = [lookup imageFromCurrentlyProcessedOutput];
But it doesn't work, it crashes like this:
Assertion failure in -[GPUImageLookupFilter createFilterFBOofSize:], PathToSource/GPUImageFilter.m:369
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Incomplete filter FBO: 36054'
I definitely need to initialize something else, but ... . So, can anyone help me to make this small piece of code work? Thanks in advance.
回答1:
Thanks to Brad Larson for answering:
For one thing, you're adding both of your images to texture location 1, so one is overriding the other. You need to add your input image to texture location 0 and lookup pattern to location 1, I believe.
回答2:
This is how I personally use it:
- (UIImage *)filterImage:(GPUImagePicture *)originalImageSource withLUTNamed:(NSString *)lutName
{
GPUImagePicture *lookupImageSource = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:lutName]];
GPUImageLookupFilter *lookupFilter = [[GPUImageLookupFilter alloc] init];
[originalImageSource addTarget:lookupFilter];
[lookupImageSource addTarget:lookupFilter];
[lookupFilter useNextFrameForImageCapture];
[originalImageSource processImage];
[lookupImageSource processImage];
return [lookupFilter imageFromCurrentFramebufferWithOrientation:UIImageOrientationUp];
}
来源:https://stackoverflow.com/questions/15965948/how-to-use-gpuimagelookupfilter-without-gpuimagefiltergroup