Sorry, if offtopic. I&#39;m not aware of GEM functionalities, but the algorythmic way to solve the problem, as I can see it, is:<br>
<br>
compute diff(x,y)=f(t,x,y)-f(t-1,x,y), where f(t) is picture at present moment;<br>
compute alpha layer for the current picture alpha(x,y)=(diff(x,y)!=(0,0,0))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
for example, in C code the predicate &quot;pixel difference does not equal
zero&quot; could be written as<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
char tmp = (char)(diff[x,y].red | diff[x,y].green | diff[x,y].blue);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
alpha[x,y] = (unsigned char)((tmp | -tmp) &gt;&gt; 7); /* the result
is: 0 for 0 and 255 otherwise */;<br>
blend initial background and current picture with computed alpha layer.<br>
<br>
The second step requires per-pixel computations and takes 5
byte-arithmetics per pixel (3 bitwise ORs, signed shiftright and
negation, which in turn could be expanded to bitwise NOT and
subtraction, machine-dependent), thus on a 320x240 24bpp picture taking
overall 384000 (or 460800, with subtractions from the first step)
integer byte-arithmetics, which is three of five orders of magnitude
below the performance of modern CPUs.<br>
Hmmm... what am I talking about?..<br>