All pastes #1718571 Raw Edit

Python

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