我使用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];
答案 0 :(得分:1)
那是因为你实际上并没有在灰度输出上运行平均颜色操作。
了解您如何定位过滤器。您将摄像机的输出直接发送到平均颜色操作。您需要将灰度滤镜的输出发送到平均颜色操作。