Sorry, if offtopic. I'm not aware of GEM functionalities, but the algorythmic way to solve the problem, as I can see it, is:
compute diff(x,y)=f(t,x,y)-f(t-1,x,y), where f(t) is picture at present moment;
compute alpha layer for the current picture alpha(x,y)=(diff(x,y)!=(0,0,0))
for example, in C code the predicate "pixel difference does not equal
zero" could be written as
char tmp = (char)(diff[x,y].red | diff[x,y].green | diff[x,y].blue);
alpha[x,y] = (unsigned char)((tmp | -tmp) >> 7); /* the result
is: 0 for 0 and 255 otherwise */;
blend initial background and current picture with computed alpha layer.
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.
Hmmm... what am I talking about?..