I am trying to use the GPUImageChromaKeyFilter according to the FilterShowcase app from GPUImage examples, but obviously I am missing something because it crashes.
Here is my code:
videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
GPUImageChromaKeyFilter *filter = [[GPUImageChromaKeyFilter alloc] init];
[filter setColorToReplaceRed:0.0 green:1.0 blue:0.0];
videoView = [[GPUImageView alloc] initWithFrame:CGRectMake(0, 0, 640, 480)];
UIImage *inputImage = [UIImage imageNamed:@"bedroom.jpeg"];
GPUImagePicture *sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
blendFilter.mix = 1.0;
When I run it, it just tells this:
2013-06-24 15:24:45.369 GPUImage Test[1284:1703] * Assertion failure
in -[GPUImageAlphaBlendFilter createFilterFBOofSize:],
2013-06-24 15:24:45.383 GPUImage Test[1284:1703] * Terminating app
due to uncaught exception 'NSInternalInconsistencyException', reason:
'Incomplete filter FBO: 36054'
* First throw call stack:
(0x3134f3e7 0x391d9963 0x3134f29d 0x31c25fa3 0xc9563 0xd608d 0xc8b3d
0xc9885 0xdaa63 0xcc11f 0xdb39f 0xca07b 0xcc153 0xd266f 0xd2dbb
0xd3f35 0x395f3793 0x395f6b3b 0x395f467d 0x395f7613 0x395f77d9
libc++abi.dylib: terminate called throwing an exception
Does anybody see what I do wrong?
Thanks in advance.
-processImage is asynchronous. It won't run to completion when you call it, so you need to maintain the filter structure until it finishes processing.
This means that you can't call
-removeTarget: right afterwards, and also means that you'll need for your
sourcePicture instance to hang around as an instance variable until the processing is completed. Otherwise, it will be deallocated at the end of this method and will tear down its outputs as a result.
You want to set up your filter chain and run
-processImage when everything's configured properly. You need to maintain the source picture for as long as you need the filtered result.