我正在尝试使用 GPUImage 制作绿屏效果。我想要达到的效果是播放窗帘打开的电影,并用图像替换电影的白色部分。这将显示窗帘,然后窗帘打开以显示图像。
我的电影显示正确,电影的白色部分和黑色一样,但是当窗帘打开时图像不显示。有人可以看看下面的代码并告诉我我做错了什么吗?
提前致谢。格雷格
NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:@"CurtainsOpening" withExtension:@"m4v"];
GPUImageMovie *movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL];
movieFile.playAtActualSpeed = YES;
NSLog(@"movie file = %@", movieFile);
GPUImageChromaKeyBlendFilter *filter = [[GPUImageChromaKeyBlendFilter alloc] init];
[(GPUImageChromaKeyBlendFilter *)filter setColorToReplaceRed:1.0 green:1.0 blue:1.0];
[(GPUImageChromaKeyBlendFilter *)filter setThresholdSensitivity:0.0]; //was 0.4
[movieFile addTarget:filter];
UIImage *inputImage = [UIImage imageNamed:@"curtains.jpg"];
NSLog(@"inputImage = %@", inputImage);
GPUImagePicture *overlayPicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
NSLog(@"overlayPicture = %@", overlayPicture);
[overlayPicture processImage];
[overlayPicture addTarget:filter];
//[movieFile addTarget:overlayPicture];
GPUImageView *view0 = [[GPUImageView alloc] initWithFrame:self.view.frame];
[view0 setFillMode:kGPUImageFillModeStretch];
NSLog(@"view0 = %@", view0);
[filter addTarget:view0];
[self.view addSubview:view0];
[view0 bringSubviewToFront:self.view];
NSLog(@"frame = %f %f", self.view.frame.size.width, self.view.frame.size.height);
[movieFile startProcessing];