我正在尝试使用 GPUImage 框架的色键过滤器。我遵循了 Filtershowcase 示例,但显然我错过了一些东西,因为它只显示视频,但没有绿屏抠像效果。这是我对摄像机/过滤器的初始化:
camera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480
cameraPosition:AVCaptureDevicePositionBack];
camera.outputImageOrientation = UIInterfaceOrientationLandscapeLeft;
camera.horizontallyMirrorFrontFacingCamera = NO;
camera.horizontallyMirrorRearFacingCamera = NO;
chromaKeyFilter = [[GPUImageChromaKeyFilter alloc] init];
chromaKeyFilter.thresholdSensitivity = sliderThres.value;
UIImage *inputImage = [UIImage imageNamed:@"WID-small.jpg"];
GPUImagePicture *sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage
smoothlyScaleOutput:YES];
[camera addTarget:chromaKeyFilter];
[sourcePicture addTarget:chromaKeyFilter];
[sourcePicture processImage];
[chromaKeyFilter addTarget:viewCamera];
[camera startCameraCapture];
所以camera和sourcePicture都输入过滤器,过滤器比进入viewCamera。但现在,我只看到纯视频,没有色键效果。(我有一个改变阈值的滑块)。
使用 GPUImageChromaKeyBlendFilter更新
camera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
camera.outputImageOrientation = UIInterfaceOrientationLandscapeLeft;
chromaKeyFilter = [[GPUImageChromaKeyBlendFilter alloc] init];
UIImage *inputImage;
inputImage = [UIImage imageNamed:@"WID-small.jpg"];
GPUImagePicture *sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
[camera addTarget:chromaKeyFilter];
[sourcePicture processImage];
[sourcePicture addTarget:chromaKeyFilter];
[chromaKeyFilter addTarget:viewCamera];
[camera startCameraCapture];
使用此滤镜,它只是将其替换为黑色,而不是实际图像。