使用GPUImageFilterGroup过滤图像将返回nil

时间:2015-10-28 19:06:47

标签: ios objective-c swift uiimage gpuimage

我将GPUImageFilterGroup子类化为一个名为SEFilter的类。

SEFilter.h文件

#import "GPUImageFilterGroup.h"
#import "GPUImagePicture.h"
#import "GPUImageLookupFilter.h"
#import "GPUImageBilateralFilter.h"

@class GPUImagePicture;

@interface SEFilter : GPUImageFilterGroup
{
    GPUImagePicture *lookupImageSource;
}

@property (nonatomic, strong) NSString *filterName;

-(id)initWithImage:(UIImage *)image filterName:(NSString *)name;

@end

SEFiletr.m文件

#import "SEFilter.h"
#import "GPUImageVignetteFilter.h"
#import "GPUImageGaussianSelectiveBlurFilter.h"
#import "GPUImageOpacityFilter.h"

@implementation SEFilter

-(id)initWithImage:(UIImage *)image filterName:(NSString *)name {
    if (!(self = [super init]))
    {
        return nil;
    }
    self.filterName = name;
    lookupImageSource = [[GPUImagePicture alloc] initWithImage:image];
    GPUImageLookupFilter *lookupFilter = [[GPUImageLookupFilter alloc] init];

    [lookupImageSource addTarget:lookupFilter atTextureLocation:1];
    [lookupImageSource processImage];

    //Clean the face
    GPUImageBilateralFilter *faceCleanFilter = [[GPUImageBilateralFilter alloc] init];
    faceCleanFilter.distanceNormalizationFactor = 20.0;

//  GPUImageVignetteFilter *vignetteFilter = [[GPUImageVignetteFilter alloc] init];
//  vignetteFilter.vignetteStart = 0.5;

    GPUImageGaussianSelectiveBlurFilter *testFilter = [[GPUImageGaussianSelectiveBlurFilter alloc] init];
    testFilter.blurRadiusInPixels = 3.0f;
    testFilter.excludeCircleRadius = 0.6;
    testFilter.excludeBlurSize = 0.5;

    [self addFilter:faceCleanFilter];
    [self addFilter:lookupFilter];
    [self addFilter:testFilter];

    [faceCleanFilter addTarget:lookupFilter];
    [lookupFilter addTarget:testFilter];


    self.initialFilters = [NSArray arrayWithObject:faceCleanFilter];
    self.terminalFilter = testFilter;

    return self;
}

@end

要创建新过滤器,我只需使用查找图像初始化此类。此机制用于过滤实时视频。但是当我尝试过滤UIImage时,过滤后的图像变为零。我使用以下代码来过滤UIImage

let filter = SEFilter(image: UIImage(named: "test"), filterName: "Test")
    if let theImage = image {
        let stillImage = GPUImagePicture(image: theImage)
        filter.useNextFrameForImageCapture()
        stillImage.addTarget(filter)
        stillImage.processImage()

        let filteredImage = filter.imageFromCurrentFramebuffer()
        imageView.image = filteredImage
    }

这里,filter是SEFilter的一个实例。此函数后imageView.image为零。我在我的项目中使用了swift和objective c。因此,一些代码是快速的,一些是客观的。我在这里做错了吗?提前谢谢。

0 个答案:

没有答案