2012-11-19 70 views
2

我想使用GPUImage框架的色度键过滤器。我遵循了Filtershowcase示例,但显然我错过了某些内容,因为它只显示视频,但没有绿屏输出效果。这里是我的摄像机/过滤器的初始化:GPUImage色度键过滤器

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]; 

所以相机和sourcePicture都送入过滤器,过滤器比进入大画幅相机。但现在,我只能看到简单的视频,没有色度键效果。 (我有一个滑块来改变阈值)。

修订与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]; 

有了这个过滤器,它只是采用黑色,而不是实际的图像取代它。

回答

0

您是否设置了滑块的目标和选择器?

这为我工作

希望有所帮助。

+0

是的,但设置的阈值没有任何关系,无论如何,即使我没有作为默认值是0.4 – 0xSina

1

我想你想GPUImageChromaKeyBlendFilter,而不是GPUImageChromaKeyFilter。

混合处理两个源图像,并将第一个图像中的键控颜色与第二个图像中的像素匹配。常规色度键控过滤器简单地将与目标色彩匹配的像素的alpha通道减少到0.0,但不混合到另一个图像中。

+0

谢谢,我做到了。但现在它将绿色替换为黑色,而不是图像。我更新了代码。我想我正在做一些错误的管道工作...... – 0xSina

+0

@ 0xSina - 你确定WID-small.jpg作为资源被正确地复制到你的应用程序的包中吗?如果是这样,在添加完所有目标之后,也尝试移动'[sourcePicture processImage];'行。 –

+0

是的,我NSLog的UIImage,它打印''。我尝试将它放在所有目标之后,但仍然不会显示图像。只是黑色的键入区域。这很奇怪,因为我正在做的是你在做什么在FilterShowcase中,它在那里工作,但不是在我的项目中... – 0xSina

1

与原始问题类似,我想在自定义视图层次结构上添加一个绿色屏幕视频。实况视频。原来,这是标准GPUImage ChromaKey过滤器无法实现的。它将混合绿色像素和背景像素,而不是alpha混合。例如,红色背景变成黄色,蓝色变成青色。

得到它的工作方式包括两个步骤:

1)确保filterview具有透明背景:

filterView.backgroundColor=[UIColor clearColor]; 

2)修改GPUImageChromaKeyFilter.m

old: gl_FragColor = vec4(textureColor.rgb, textureColor.a * blendValue); 

new: gl_FragColor = vec4(textureColor.rgb * blendValue, 1.0 * blendValue); 

现在视频中的所有键控(例如绿色)像素都变为透明并发现过滤器视图下的所有内容,包括(在线 - )视频。

+0

其实,这是一个类似的问题.. http://stackoverflow.com/questions/12462805/chroma-filtering-video-using-gpuimage/16169412#16169412 – Frans

相关问题