Chaining GPUImageChromaKeyBlendFilter

4 replies [Last post]
michel.lonngren
User offline. Last seen 7 years 44 weeks ago. Offline
Joined: 08/01/2012
Posts:

I started playing around with GPUImage yesterday and I am impressed. I was up using it in matter of minutes, but today I have been struggling with chaining the GPUImageChromaKeyBlendFilter filter.

currently I am doing something similar to.

[chroma1 addTarget:chroma2];
[foreground addTarget:chroma1];
[foreground processImage];

[background addTarget:chroma1];
[background processImage];

return [chroma1 imageFromCurrentlyProcessedOutput];

For one filter (only having chroma1) this technique is working but not for 2 or more.

Any ideas is much apprechiated.

michel.lonngren
User offline. Last seen 7 years 44 weeks ago. Offline
Joined: 08/01/2012
Posts:

I finally got it working by doing the following:

[foreground addTarget:chroma1];
[foreground addTarget:chroma2];

[foreground processImage];
[background addTarget:chroma1];
[background processImage];

[foreground processImage];
[background addTarget:chroma2];
[background processImage];

return[chroma1 imageFromCurrentlyProcessedOutput];

Seems a bit wasteful to run processimage twice on each image. Am I doing things backwards? Is there a more effective way to do this?

(I see a pretty harsh slowdown for each new chroma filter I add).

Brad Larson
Brad Larson's picture
User offline. Last seen 4 years 22 weeks ago. Offline
Joined: 05/14/2008
Posts:

Try reordering it to this:

[foreground addTarget:chroma1];
[foreground addTarget:chroma2];
 
[background addTarget:chroma1];
 
[background addTarget:chroma2];
 
[foreground processImage];
[background processImage];

Under the new way that I've configured the blends, this should ripple down the filter chain appropriately.

michel.lonngren
User offline. Last seen 7 years 44 weeks ago. Offline
Joined: 08/01/2012
Posts:

Thanks that seems to work fine and is much faster.

Another related question. It seems like the thresholdSensitivity setting responds quite differently to different colors. Red requires a very low threshold to be replaces whereas blue and green seem to be quite hard to replace and need a higher threshold.

This seems a bit odd to me, but maybe I am doing something wrong.

Brad Larson
Brad Larson's picture
User offline. Last seen 4 years 22 weeks ago. Offline
Joined: 05/14/2008
Posts:

The color "distances" are based on Y, Cb, and Cr, and are based on a distance algorithm proposed by Apple in one of their samples. You can look at the fragment shader code to see how I calculate this. There might be a better way to calculate this, but that's what I'm using right now.

Syndicate content