来自GPUImageStillCamera源的GPUImageAlphaBlendFilter实时处理 [英] GPUImageAlphaBlendFilter realtime processing from GPUImageStillCamera source

查看:222
本文介绍了来自GPUImageStillCamera源的GPUImageAlphaBlendFilter实时处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GPUImage库,并且试图实时混合两个图像,并将它们显示在GPUImageView上.我正在尝试将Alpha混合的普通摄像机输入与其过滤后的版本一起使用.这是我想要做的:

I am using the GPUImage library and I'm trying to blend two images in realtime, and display them on a GPUImageView. I am trying to alpha-blend plain camera input, with a filtered version of it. Here is what I'm trying to do:

          ----------------->----v
--camera--|                     alpha blend ----> image view
          -----> color filter --^

我发现了一些有关使用混合过滤器的帖子,但是它们似乎不是实时处理的方法.我发现 https://github.com/BradLarson/GPUImage/issues/319 GPUImage:混合两个图像

I've found some posts about using the blend filters, but they don't seem to be methods for realtime processing. I've found https://github.com/BradLarson/GPUImage/issues/319, GPUImage: blending two images, and https://github.com/BradLarson/GPUImage/issues/751 (but they either aren't for realtime processing, (first and the second), or doesn't work (third one).

我几乎已经尝试了所有方法,但是得到的只是GPUImageView中的白色图像.如果我不使用alpha混合滤镜,例如,使用假彩色滤镜或类似的滤镜,它会完美地工作.这是我的代码:

I've tried almost everything, but all I'm getting is a white image in the GPUImageView. If I don't use the alpha blend filter, say, just use a false color filter or something similar, it works perfectly. Here is my code:

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];,则会在图像上显示错误的彩色滤光片.

All I'm getting is a white, blank screen. If I change [selectedFilter addTarget:blendFilter]; to [selectedFilter addTarget:imageView]; then false color filter gets displayed on the image.

alpha混合滤镜似乎有问题.我已经读过一些文章,我需要在输入中调用processImage,但是据我所知,这些文章都是用于非实时输入的.如何使GPUImageAlphaBlendFilter实时工作?

There seems to be something wrong with the alpha blend filter. I've read that in some posts that I need to call processImage on the inputs, but those posts are all for non-realtime inputs as far as I understand. How can I get GPUImageAlphaBlendFilter to work in realtime?

推荐答案

好,在通过互联网并在项目的问题列表上进一步调查了问题之后( https://github.com/BradLarson/GPUImage/issues ),并找到了解决方法.将混合滤镜设置为目标时,我需要专门指定纹理索引.由于某种原因(可能是一个错误),两次添加目标混合过滤器不会在下一个索引处正确添加第二个纹理.因此,将纹理索引显式设置为0和1确实可行:

Ok, after investigating the issue further over the internet and on project's issue list (https://github.com/BradLarson/GPUImage/issues) and found a workaround. While setting the blend filter as the target, I needed to specify the texture index specifically. For some reason (probably a bug), adding the target blend filter two times doesn't add the second texture correctly at the next index. So setting the texture indices explicitly as 0 and 1 did work:

[passThrough addTarget:blendFilter atTextureLocation:0];
[selectedFilter addTarget:blendFilter atTextureLocation:1];

对于作为单一来源目标的过滤器,尽管addTarget:就足够了,例如[stillCamera addTarget:selectedFilter];.

For the filters that are targets of single sources, addTarget: is enough though such as [stillCamera addTarget:selectedFilter];.

这篇关于来自GPUImageStillCamera源的GPUImageAlphaBlendFilter实时处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆