Blending using GPUImagePoissonBlendFilter

陌路散爱 提交于 2019-12-06 23:33:30

问题


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

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).

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?


回答1:


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

Try this:

[picture1 addTarget:poissonFilter atTextureLocation:0];

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.



来源:https://stackoverflow.com/questions/17922327/blending-using-gpuimagepoissonblendfilter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!