How to use GPUImageLookupFilter without GPUImageFilterGroup?

本秂侑毒 提交于 2019-12-21 20:30:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!