-
Notifications
You must be signed in to change notification settings - Fork 0
/
picam.py
45 lines (37 loc) · 1.22 KB
/
picam.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
from picamera import PiCamera
from picamera.array import PiRGBArray
from threading import Thread
class camera:
def __init__(self, resolution=(320, 240), framerate=32):
self.cam = PiCamera()
self.cam.resolution = resolution
self.cam.framerate = framerate
self.rawCapture = PiRGBArray(self.cam, size=resolution)
self.stream = self.cam.capture_continuous(self.rawCapture, format="bgr", use_video_port=True)
self.frame = None
self.stopped = False
self.paused = False
def start(self):
Thread(target=self.update, args=()).start()
return self
def update(self):
for f in self.stream:
while self.paused:
pass
self.frame = f.array
self.rawCapture.truncate(0)
if self.stopped:
self.stream.close()
self.rawCapture.close()
self.cam.close()
print("Camera Thread Stopped")
return
def read(self):
return self.frame
def release(self):
self.paused = False
self.stopped = True
def pause(self):
self.paused = True
def resume(self):
self.paused = False