-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideocontrol.py
66 lines (54 loc) · 1.8 KB
/
videocontrol.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pygame
import pygame.camera
from pygame.locals import *
import time as time
pygame.init()
pygame.camera.init()
class Capture(object):
def __init__(self):
self.size = (640,480)
# create a display surface. standard pygame stuff
self.display = pygame.display.set_mode(self.size, 0)
# this is the same as what we saw before
self.clist = pygame.camera.list_cameras()
if not self.clist:
raise ValueError("Sorry, no cameras detected.")
self.cam = pygame.camera.Camera(self.clist[0], self.size)
self.cam.start()
# create a surface to capture to. for performance purposes
# bit depth is the same as that of the display surface.
self.snapshot = pygame.surface.Surface(self.size, 0, self.display)
self.get_and_flip()
def get_and_flip(self):
# if you don't want to tie the framerate to the camera, you can check
# if the camera has an image ready. note that while this works
# on most cameras, some will never return true.
if self.cam.query_image():
self.snapshot = self.cam.get_image(self.snapshot)
# blit it to the display surface. simple!
self.display.blit(self.snapshot, (0,0))
pygame.display.flip()
def main(self):
going = True
while going:
events = pygame.event.get()
for e in events:
if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
# close the camera safely
self.cam.stop()
going = False
self.get_and_flip()
# def loopVideo():
# while(1):
# size = (640,480)
# # create a display surface. standard pygame stuff
# display = pygame.display.set_mode(size, 0)
# # this is the same as what we saw before
# clist = pygame.camera.list_cameras()
# if not clist:
# raise ValueError("Sorry, no cameras detected.")
# cam = pygame.camera.Camera(clist[0], size)
# cam.start()
newStream = Capture()
newStream.get_and_flip()
time.sleep(10)