我正在使用GPUImage库,我正在尝试实时地混合两个图像,并在GPUImageView上显示它们。我正在尝试将普通相机输入与过滤后的版本进行alpha混合。这是我想要做的:
----------------->----v
--camera--| alpha blend ----> image view
-----> color filter --^我找到了一些关于使用混合滤镜的帖子,但它们似乎不是实时处理的方法。我找到了https://github.com/BradLarson/GPUImage/issues/319、GPUImage: blending two images和https://github.com/BradLarson/GPUImage/issues/751 (但它们要么不支持实时处理(第一个和第二个),要么不能工作(第三个)。
我几乎什么都试过了,但我在GPUImageView上得到的只是一张白色图像。如果我不使用alpha混合滤镜,比如说,只使用假彩色滤镜或类似的东西,它就可以完美地工作。下面是我的代码:
blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
blendFilter.mix = 0.5;
[blendFilter prepareForImageCapture];
[blendFilter addTarget:imageView];
passThrough = [[GPUImageFilter alloc] init];
[passThrough prepareForImageCapture];
[passThrough addTarget:blendFilter];
selectedFilter = [[GPUImageFalseColorFilter alloc] init];
[selectedFilter prepareForImageCapture];
[selectedFilter addTarget:blendFilter];
stillCamera = [[GPUImageStillCamera alloc] init];
stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
[stillCamera addTarget:passThrough];
[stillCamera addTarget:selectedFilter];
[stillCamera startCameraCapture];我看到的只是一个白色的空白屏幕。如果我将[selectedFilter addTarget:blendFilter];更改为[selectedFilter addTarget:imageView];,则错误的滤色器将显示在图像上。
alpha混合滤镜似乎有问题。我在一些文章中读到,我需要在输入上调用processImage,但据我所知,这些文章都是针对非实时输入的。如何让GPUImageAlphaBlendFilter实时工作?
发布于 2013-05-13 21:05:58
好的,在通过互联网和项目的问题列表(https://github.com/BradLarson/GPUImage/issues)进一步调查了这个问题并找到了解决方法后。在将混合滤镜设置为目标时,我需要特别指定纹理索引。由于某些原因(可能是bug),添加目标混合滤镜两次并不能在下一个索引处正确添加第二个纹理。因此,将纹理索引显式设置为0和1确实有效:
[passThrough addTarget:blendFilter atTextureLocation:0];
[selectedFilter addTarget:blendFilter atTextureLocation:1];对于作为单源目标的过滤器,尽管如[stillCamera addTarget:selectedFilter];,addTarget:就足够了。
https://stackoverflow.com/questions/16384813
复制相似问题