GPUImageHistogramFilter用于静态图像,提供零数据

时间:2013-03-20 22:21:31

标签: ios objective-c image-processing gpuimage

与此answer非常相似,除了我想为静止图像生成直方图。

以下是我正在做的事情,并且它给出了所有0数据的直方图。让这个工作有一些技巧吗?

GPUImageFilter *filter = [[GPUImageHistogramFilter alloc]  initWithHistogramType:kGPUImageHistogramRGB];

GPUImagePicture *original = [[[GPUImagePicture alloc] initWithImage:image] autorelease];

GPUImageGammaFilter *gammaFilter = [[GPUImageGammaFilter alloc] init];
[original addTarget:gammaFilter];
[gammaFilter addTarget:filter];

GPUImageHistogramGenerator *histogramGraph = [[GPUImageHistogramGenerator alloc] init];

[histogramGraph forceProcessingAtSize:CGSizeMake(256.0, 330.0)];
[filter addTarget:histogramGraph];

GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
blendFilter.mix = 0.75;
[blendFilter forceProcessingAtSize:CGSizeMake(256.0, 330.0)];

[original addTarget:blendFilter];
[histogramGraph addTarget:blendFilter];

[blendFilter addTarget:gpuImageView];

[original processImage];

1 个答案:

答案 0 :(得分:0)

Brad已经将一些内部机制更改为GPUImage以改进内存管理(并且确实如此),现在您应该告诉过滤器保留静止图像的帧-useNextFrameForImageCapture

UIImage *inputImage = [UIImage imageNamed:@"Lambeau.jpg"];

GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];

[stillImageSource addTarget:stillImageFilter];
[stillImageFilter useNextFrameForImageCapture]
[stillImageSource processImage];

UIImage *currentFilteredVideoFrame = [stillImageFilter imageFromCurrentFramebuffer];