3
# 1. Basic image capturing and displaying using the camera module
7
from pygame.locals import *
10
class VideoCapturePlayer(object):
13
def __init__(self, **argd):
14
self.__dict__.update(**argd)
15
super(VideoCapturePlayer, self).__init__(**argd)
17
# create a display surface. standard pygame stuff
18
self.display = pygame.display.set_mode( self.size, 0 )
20
# gets a list of available cameras.
21
self.clist = pygame.camera.list_cameras()
23
raise ValueError("Sorry, no cameras detected.")
25
# creates the camera of the specified size and in RGB colorspace
26
self.camera = pygame.camera.Camera(self.clist[0], self.size, "RGB")
31
self.clock = pygame.time.Clock()
33
# create a surface to capture to. for performance purposes, you want the
34
# bit depth to be the same as that of the display surface.
35
self.snapshot = pygame.surface.Surface(self.size, 0, self.display)
37
def get_and_flip(self):
38
# if you don't want to tie the framerate to the camera, you can check and
39
# see if the camera has an image ready. note that while this works
40
# on most cameras, some will never return true.
41
if 0 and self.camera.query_image():
44
self.snapshot = self.camera.get_image(self.snapshot)
45
self.snapshot = self.camera.get_image(self.snapshot)
46
#self.snapshot = self.camera.get_image()
48
# blit it to the display surface. simple!
49
self.display.blit(self.snapshot, (0,0))
55
events = pygame.event.get()
57
if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
62
print (self.clock.get_fps())
67
VideoCapturePlayer().main()
70
if __name__ == '__main__':