GPUImage平均颜色与应用的灰度滤镜不匹配

时间:2015-02-11 08:25:30

标签: ios objective-c iphone gpuimage

我使用GPUImage遇到以下问题: 1我正在为相机添加灰度滤镜,然后我使用GPUImageAverageColor来获得平均颜色。问题是我通过块的颜色不是灰度范围。我做错了什么?

这是代码:

    GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

    GPUImageView *filterView = (GPUImageView *)self.cameraLayer;
    [filterView setFillMode:kGPUImageFillModePreserveAspectRatioAndFill];

    GPUImageGrayscaleFilter *grayscaleFilter = [[GPUImageGrayscaleFilter alloc] init];
    [videoCamera addTarget:grayscaleFilter];
    [grayscaleFilter addTarget:filterView];

    GPUImageAverageColor *averageColor = [[GPUImageAverageColor alloc] init];
    [averageColor setColorAverageProcessingFinishedBlock:^(CGFloat redComponent, CGFloat greenComponent, CGFloat blueComponent, CGFloat alphaComponent, CMTime frameTime){

        NSLog(@"Red: %f, green: %f, blue: %f, alpha: %f", redComponent, greenComponent, blueComponent, alphaComponent);

    }];

    [videoCamera addTarget:averageColor];
    [videoCamera startCameraCapture];

1 个答案:

答案 0 :(得分:1)

那是因为你实际上并没有在灰度输出上运行平均颜色操作。

了解您如何定位过滤器。您将摄像机的输出直接发送到平均颜色操作。您需要将灰度滤镜的输出发送到平均颜色操作。