使用GPUImagePoissonBlendFilter进行混合 [英] Blending using GPUImagePoissonBlendFilter

查看:458
本文介绍了使用GPUImagePoissonBlendFilter进行混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用GPUImage框架的GPUImagePoissonBlendFilter来混合我的面部混合应用程序中的两个面。这是我的代码。

Im trying to use GPUImagePoissonBlendFilter of the GPUImage framework to blend two faces in my face blending application. Here is my code.

- (void)applyPoissonBlendToImage:(UIImage *) rearFace withImage:(UIImage *) frontFace 
{  
       GPUImagePicture* picture1 = [[GPUImagePicture alloc] initWithImage:rearFace];
       GPUImagePicture* picture2 = [[GPUImagePicture alloc] initWithImage:frontFace];

       GPUImagePoissonBlendFilter * poissonFilter = [[GPUImagePoissonBlendFilter alloc] init];
       poissonFilter.mix = .7;
       poissonFilter.numIterations = 200;

       [picture1 addTarget:poissonFilter];
       [picture1 processImage];

       [picture2 addTarget:poissonFilter];
       [picture2 processImage];

      finalResultImage = [poissonFilter imageFromCurrentlyProcessedOutputWithOrientation:rearFace.imageOrientation];
   }

ie如你所见,我给的是两张图片(backFace和frontFace)作为此方法的输入。图像正面是一种形状(通过连接相对的眼睛和嘴部位置形成的多边形形状),并且与后面的图像i .e相同(为了匹配尺寸,我填充了多边形外部的空间)在绘图时使用透明色。)

i.e As you can see, I am giving two images (rearFace and frontFace) as inputs to this method. The image front face is a shape (polygon shape formed by joining relative eye's and mouth postion's) and is of the same size as the rearFace image i .e (To match the size, I've filled the the space external to the polygonal shape with transparent color while drawing).

然而,混合不会像我预期的那样发生。即前面的锋利边缘没有适当地混入后面。在这里,我的假设是PoissonBlendFilter开始从其左上角而不是脸的左上边界开始混合第二个图像。

However blending does not happen as I expected. i.e the sharp edges of the front face are not blended into rear face properly. Here my assumption is that the PoissonBlendFilter starts blending second image from its top left corner rather than the top left boundary of the face.

问题:我觉得输入图像是未正确送入过滤器。我是否需要对输入图像应用某种掩模?任何人都可以指导我吗?

Problem:I feel that the input image is not fed into the filter correctly . Do I need to apply some kind of masking to the input image? Can anyone guide me in this?

推荐答案

使用双输入过滤器时,GPUImage有时会变得棘手。将混合滤镜添加到第一个源图像时,请明确指定纹理位置。所以代替:

GPUImage can sometimes become tricky with two-input filters. When you are adding the blend filter to the first source image, specify the texture location explicitly. So instead of:

[picture1 addTarget:poissonFilter];

试试这个:

[picture1 addTarget:poissonFilter atTextureLocation:0];

其余的( picture1 或其他任何人)不需要这个,但是有两个输入过滤器有时需要一个小错误明确指定纹理位置。

The rest (picture1 or any others) don't need this, but there is a little bug with two input filters that sometimes require excplicitly specifying the texture location.

这篇关于使用GPUImagePoissonBlendFilter进行混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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