Exemplo n.º 1
0
class PictureFrames(AetherModule) :

	def __init__(self,*args) :
		# need to call parent class' init method explicitly in python
		AetherModule.__init__(self,*args)
		self.font = pygame.font.Font(None,24)
		self.frame = pygame.image.load("frames.png")
		self.frame_coords = ((82,94),(334,94),(454,94),(454,260),(334,260))
		self.frame_scales = ((229,302),(98,136),(98,136),(100,136),(100,136))

		self.frame_sprites = []
		self.frame_sprites.append(FaceSprite(pygame.Rect((0,0),(0,0)),lag=10))

		self.sprite_tracker = FaceSpriteTracker(max_sprites=5,tolerance=(100,100))

	def draw(self,screen) :

		raw_image = self.input.get_curr_frame()
		#raw_image = self.input.get_fd_frame()
		scaled_raw_image = pygame.transform.scale(raw_image,self.dims)
		#screen.blit(scaled_raw_image,(0,0))
		#screen.blit(raw_image,(0,0))

		faces = self.input.get_polys()
		#faces = []
		screen.blit(self.frame,(0,0))

		if len(faces) > 0 :

			for i,face in enumerate(faces) :
				face = [(int(x[0]*self.dims[0]),int(x[1]*self.dims[1])) for x in face]
				dims = face[1][0]-face[0][0], face[2][1]-face[1][1]
				faces[i] = pygame.Rect(face[0],dims)

		self.sprite_tracker.update(faces,scaled_raw_image)

		print 'Sprite ages:',self.sprite_tracker._sprite_ages
		for i,sprite in enumerate(self.sprite_tracker.sprites) :
			scaled_face_surf = pygame.transform.scale(sprite.image,self.frame_scales[i])
			screen.blit(scaled_face_surf,self.frame_coords[i])
			num = self.font.render(str(i),False,THECOLORS['red'])
			screen.blit(num,self.frame_coords[i])
Exemplo n.º 2
0
	def __init__(self,*args) :
		# need to call parent class' init method explicitly in python
		AetherModule.__init__(self,*args)
		self.font = pygame.font.Font(None,24)
		self.frame = pygame.image.load("frames.png")
		self.frame_coords = ((82,94),(334,94),(454,94),(454,260),(334,260))
		self.frame_scales = ((229,302),(98,136),(98,136),(100,136),(100,136))

		self.frame_sprites = []
		self.frame_sprites.append(FaceSprite(pygame.Rect((0,0),(0,0)),lag=10))

		self.sprite_tracker = FaceSpriteTracker(max_sprites=5,tolerance=(100,100))
Exemplo n.º 3
0
class FaceTiler(AetherModule) :

	chains={'faces':'FacesChain','camera':'ScaledCameraChain'}

	def init(self):
		self.grid = (3,2)
		self.pane_size = (self.dims[0]/self.grid[0],self.dims[1]/self.grid[1])
		self.grid_coords = [(i*self.pane_size[0],j*self.pane_size[1]) for i in range(self.grid[0]) for j in range(self.grid[1])]

		self.sprite_tracker = FaceSpriteTracker(max_sprites=len(self.grid_coords),tolerance=self.pane_size,maxwait=5,replace_policy=FaceSpriteTracker.RANDOM,fill=True)

	def draw(self,screen) :

		frame=self.camera.read()

		screen.fill(THECOLORS["black"])

		faces = self.faces.read()

		for i,face in enumerate(faces) :
			dims = face[1][0]-face[0][0], face[2][1]-face[1][1]
			faces[i] = pygame.Rect(face[0],dims)

		self.sprite_tracker.update(faces,frame)

		for i,sprite in enumerate(self.sprite_tracker.sprites) :
			screen.blit(sprite.image,self.grid_coords[i])
			scaled_face_surf = pygame.transform.scale(sprite.image,self.pane_size)
			screen.blit(scaled_face_surf,self.grid_coords[i])

		# draw a lattice on top of the pictures
		dk_gray = (30,30,30,30)
		for i in range(self.grid[1]) :
			pygame.draw.aaline(screen,dk_gray,(0,i*self.pane_size[1]),(self.dims[0],i*self.pane_size[1]))
		for i in range(self.grid[0]) :
			pygame.draw.aaline(screen,dk_gray,(i*self.pane_size[0],0),(i*self.pane_size[0],self.dims[1]))
Exemplo n.º 4
0
	def init(self):
		self.grid = (3,2)
		self.pane_size = (self.dims[0]/self.grid[0],self.dims[1]/self.grid[1])
		self.grid_coords = [(i*self.pane_size[0],j*self.pane_size[1]) for i in range(self.grid[0]) for j in range(self.grid[1])]

		self.sprite_tracker = FaceSpriteTracker(max_sprites=len(self.grid_coords),tolerance=self.pane_size,maxwait=5,replace_policy=FaceSpriteTracker.RANDOM,fill=True)