我正在使用 GPUImage 库,我正在尝试实时混合两个图像,并将它们显示在GPUImageView
。我正在尝试将普通相机输入与其过滤版本进行 alpha 混合。这是我想做的:
----------------->----v
--camera--| alpha blend ----> image view
-----> color filter --^
我发现了一些关于使用混合过滤器的帖子,但它们似乎不是实时处理的方法。我找到了https://github.com/BradLarson/GPUImage/issues/319 https://github.com/BradLarson/GPUImage/issues/319, GPUImage:混合两个图像 https://stackoverflow.com/questions/11608332/gpuimage-blending-two-images, and https://github.com/BradLarson/GPUImage/issues/751 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];
to [selectedFilter addTarget:imageView];
然后假彩色滤镜就会显示在图像上。
Alpha 混合滤镜似乎有问题。我在一些我需要打电话的帖子中读到过processImage
关于输入,但据我了解,这些帖子都是非实时输入。如何让 GPUImageAlphaBlendFilter 实时工作?
好的,在通过互联网和项目问题列表进一步调查该问题之后(https://github.com/BradLarson/GPUImage/issues https://github.com/BradLarson/GPUImage/issues)并找到了解决方法。在将混合滤镜设置为目标时,我需要专门指定纹理索引。由于某种原因(可能是错误),添加目标混合过滤器两次不会在下一个索引处正确添加第二个纹理。因此,将纹理索引明确设置为 0 和 1 确实有效:
[passThrough addTarget:blendFilter atTextureLocation:0];
[selectedFilter addTarget:blendFilter atTextureLocation:1];
对于作为单一源目标的过滤器,addTarget:
就足够了,例如[stillCamera addTarget:selectedFilter];
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)