Because at least one of the webcams we use produces a rubbish first frame and minor lighting differences between frames (which can look pretty jumpy when we capture time-lapse movies we use the following python code to average frames 3 through 9 of the captured tga images, stick a time stamp on it, and save it as a png so we can stitch it together later into an [mpeg]] movie.
We have other programs called average.py
that do mostly similar things, so be sure to use the one that you need.
import datetime,sys
from PIL import Image
im = Image.open('00000001.tga')
result = im.copy()
pix = im.load()
result_pix = result.load()
w,h = im.size
imgs = [Image.open('0000000'+str(i)+'.tga') for i in range(3,10)]
pixs = [i.load() for i in imgs]
n = len(pixs)
for y in range(0,h):
for x in range(0,w):
sr,sg,sb = 0,0,0
for px in pixs:
r,g,b,a = px[x,y]
sr += r
sg += g
sb += b
result_pix[x,y] = (sr/n,sg/n,sb/n)
result.save(sys.argv[1]+'@'+str(datetime.datetime.now())+'.png')