Example #1
0
	def __laplace_filter__( self ):
		'''
			filtre l'image avec l'algo laplace puis la stocke dans self.laplacehim
		'''
		self.__capture_im__()
		laplaceim_jpg = transform.laplacian( self.snapshot )
		tempim = self.__pygame_to_cvimage__( laplaceim_jpg )
		cv.CvtColor( tempim, self.laplaceim, cv.CV_RGB2GRAY )
		self.image_actuel = self.laplaceim
		cv.Copy( self.laplaceim, self.image_actuel )
Example #2
0
def edgeDetectionProcess(surf):
    """This function takes a Pygame Surface detects edges in the image, and
    returns a pygame surface.
    
    """
    if useScipy:
        imageArray1 = numpy.mean(surfarray.array3d(surf),2) # converting here to one col
        if scipySpline:
            imageArray2 = edgeDetect2(imageArray1)
        else:
            imageArray2 = edgeDetect1(imageArray1)
        surf = surfarray.make_surface(imageArray2)
    else:
        # use pygame transform
        surf = transform.laplacian(surf)
    return surf
Example #3
0
def edgeDetectionProcess(surf):
    """This function takes a Pygame Surface detects edges in the image, and
    returns a pygame surface.
    
    """
    if useScipy:
        imageArray1 = numpy.mean(surfarray.array3d(surf),
                                 2)  # converting here to one col
        if scipySpline:
            imageArray2 = edgeDetect2(imageArray1)
        else:
            imageArray2 = edgeDetect1(imageArray1)
        surf = surfarray.make_surface(imageArray2)
    else:
        # use pygame transform
        surf = transform.laplacian(surf)
    return surf
Example #4
0
    def _internal_border(self, text, size, pixel_size, offset, color = None):
        """ Add an internal border (inside of the font). """

        # Use very different colors to get a very sharp edge
        BG = (0,0,0)
        FG = (255,255,255)
        temp = self._get_new_surface(text, pixel_size)
        temp.fill(BG)
        temp.blit(self._render_internal(text, size, FG, BG), offset)
        
        temp = laplacian(temp)
        temp.set_colorkey(FG)

        result = self._get_new_surface(text, pixel_size)
        result.fill(color)
        result.blit(temp, (0,0))
        result.set_colorkey(BG)
        return result
Example #5
0
def run(args):

    image = pygame.image.load(args.filepath).convert_alpha()
    background_color = args.background_color or "black"
    bg = pygame.Surface((256, 256))
    animate_size = image.get_rect()

    clock = pygame.time.Clock()


    direction = 0
    frame_speed = 8
    frame_no = 0
    frame_add = 0.0
    running = True
    if image.get_rect().height %  (8 * 256) == 0:
        has_direction = True
        frame_no_max = image.get_rect().height / 8 / 256
        print "frame_no_max: %s" % frame_no_max
    else:
        has_direction = False
        frame_no_max = image.get_rect().height / 256
        print "only one direction, frame_no_max: %s" % frame_no_max

    while running:
        for event in pygame.event.get(): # User did something
            if event.type == pygame.QUIT: # If user clicked close
                running = False
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    running = False
                elif event.key == K_t:
                    direction = (direction + 1) % 8
                elif event.key == K_UP:
                    frame_speed += 1
                elif event.key == K_DOWN:
                    frame_speed = max(0, frame_speed - 1)
                elif event.key == K_s:
                    CONTROL["stop"] = not CONTROL["stop"]
                elif event.key == K_a:
                    if CONTROL["stop"]:
                        frame_add -= 1
                elif event.key == K_d:
                    if CONTROL["stop"]:
                        frame_add += 1

        screen.fill(pygame.Color(background_color))

        time_passed = clock.tick(60)
        time_passed_seconds = time_passed / 1000.0

        if not CONTROL["stop"]:
            frame_add += time_passed_seconds * frame_speed

        frame_add %= frame_no_max

        if has_direction:
            frame_no = direction + int(frame_add) * 8
        else:
            frame_no = int(frame_add)

        blit_image = image.subsurface(pygame.Rect(
            (0, frame_no * animate_size.width, animate_size.width, animate_size.width)
        ))

        if args.laplacian:
            lap_sf = laplacian(blit_image)
            screen.blit(lap_sf, (0, 0))
            pygame.draw.rect(screen, pygame.Color("blue"), blit_image.get_bounding_rect(), 1)
        else:
            screen.blit(blit_image, (0, 0))

        frame_add_info = sfg.Font.ARIAL_32.render("frame add: %s" % int(frame_add), True, pygame.Color("white"))
        screen.blit(frame_add_info, (0, 256))

        pygame.display.update()