[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Proposed Module: Camera



On Tuesday 03 June 2008 01:27:19 Nirav Patel wrote:
...
> The code I'm working on is at http://git.n0r.org/?p=pygame-nrp;a=summary

This program, using the above code, amuses (small) children no end :-)

I know it's a trivial mod of the previous one, but it creates surprising 
levels of giggles and laughter in 4 & 6 year olds :-)

import pygame
import pygame.camera

pygame.init()

class VideoCapturePlayer(object):
    displaysize = (1024, 768)
    capturesize = ( 320, 240 )
    mirror = True
    delay = 0
    def __init__(self, **argd):
        self.__dict__.update(**argd)
        super(VideoCapturePlayer, self).__init__(**argd)
        self.display = pygame.display.set_mode( self.displaysize )
        self.camera = X=pygame.camera.Camera("/dev/video0", self.capturesize)
        self.camera.start()

    def get_and_flip(self):
        snapshot = self.camera.get_image()
        snapshot = pygame.transform.scale(snapshot,(512,384))
        if self.mirror:
            flippedx = pygame.transform.flip(snapshot,1,0)
            flippedy = pygame.transform.flip(snapshot,0,1)
            flippedxy = pygame.transform.flip(snapshot,1,1)
        self.display.blit(flippedy, (0,384))
        self.display.blit(flippedxy, (512,384))
        self.display.blit(snapshot, (0,0))
        self.display.blit(flippedx, (512,0))
        pygame.display.flip()

    def main(self):
        while 1:
            time.sleep(self.delay)
            self.get_and_flip()

VideoCapturePlayer().main()


Michael.