All pastes #1718560 Raw Edit

Python

public python v1 · immutable
#1718560 ·published 2009-12-17 19:27 UTC
rendered paste body
#!/usr/bin/env python#from VideoCapture import Deviceimport timeimport Image as imageimport ImageDrawimport mathimport numpyinterval = 2#minimum wait time between frames#cam = Device(devnum=0, showVideoWindow=1)#print "press ctrl+c at any time to abort"#cam.saveSnapshot('snap.jpg')#del cam#remove cam#time.sleep(interval)im=image.open("snap.jpg")#im=im.convert("L")"""stat=ImageStat.Stat(im)val=stat.rms[0]print valdef func(c):    global val    if(c>val):        return 255    else:        return 0nim=image.eval(im,func)""""""i = Image.open('lena.jpg')a = numpy.asarray(i) # a is readonlyi = Image.fromarray(a)cy=np.sum(f*np.arange(f.shape[0])[:,np.newaxis])/np.sum(f)cx=np.sum(f*np.arange(f.shape[1])[np.newaxis,:])/np.sum(f)"""def filter(a,axis):    return [a[0],0,0]#numpy.apply_over_axes(func, a, axes)oa=numpy.asarray(im)a=numpy.copy(oa)fuzz=10rgb=numpy.array([121,47,46])b=numpy.all(numpy.abs(a-rgb[numpy.newaxis,numpy.newaxis,:])<fuzz, axis=-1)#mask with reda[b]=[255,0,0]nim = image.fromarray(a)#calculate centrepoint and draw a markcy=numpy.sum(b*numpy.arange(b.shape[0])[:,numpy.newaxis])/numpy.sum(b)cx=numpy.sum(b*numpy.arange(b.shape[1])[numpy.newaxis,:])/numpy.sum(b)drw=ImageDraw.Draw(nim)drw.line([cx-16,cy,cx+16,cy],fill=255)drw.line([cx,cy-16,cx,cy+16],fill=255)del drwnim.show()#debug only