-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcam.py
More file actions
99 lines (85 loc) · 3.15 KB
/
Copy pathcam.py
File metadata and controls
99 lines (85 loc) · 3.15 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import io
import picamera
image_effect = [ 'none', 'negative', 'solarize', 'sketch', \
'denoise', 'emboss', 'oilpaint', 'hatch', \
'gpen', 'pastel', 'watercolor', 'film', \
'blur', 'saturation', 'colorswap', 'washedout', \
'posterise', 'colorpoint', 'colorbalance', \
'cartoon', 'deinterlace1', 'deinterlace2' ]
drc_strength = [ 'off', 'low', 'medium', 'high']
exposure_mode = [ 'off', 'auto', 'night', 'nightpreview', \
'backlight', 'spotlight', 'sports', \
'snow', 'beach', 'verylong', 'fixedfps', \
'antishake', 'fireworks']
flash_mode = [ 'off', 'auto', 'on', 'redeye', 'fillin', 'torch']
class CamOutput(io.BytesIO):
def __init__(self):
io.BytesIO.__init__(self)
self.data = None
def close(self):
super().close()
self.data = None
def truncate(self):
super().truncate()
super().seek(0)
def flush(self):
super().flush()
self.data = self.getvalue()
class VideoStream(CamOutput):
def __init__(self, resolution=(320, 240), \
video_format='bgr', \
framerate=32, \
led_pin=None):
CamOutput.__init__(self)
self.camera = picamera.PiCamera(led_pin=led_pin)
self.camera.resolution = resolution
self.camera.framerate = framerate
#self.camera.image_effect = image_effect[14]
self.stream = self.camera.capture_continuous(\
self, \
format=video_format, \
use_video_port=True)
self.size = self.camera.resolution
def __del__(self):
self.stream.close()
super().close()
self.camera.close()
def raw(self):
next(self.stream)
frame = self.data
self.truncate()
#if process(self): return b''
return frame
def capture(self):
return bytes_to_rgb(self.raw(), self.size)
def flip(self, hflip, vflip):
self.camera.hflip = hflip
self.camera.vflip = vflip
def info(self):
print('image_effect\t\t', self.camera.image_effect)
print('image_denoise\t\t', self.camera.image_denoise)
print('hflip\t\t\t', self.camera.hflip)
print('vflip\t\t\t', self.camera.vflip)
print('iso\t\t\t', self.camera.iso)
print('brightness\t\t', self.camera.brightness)
print('clock_mode\t\t', self.camera.clock_mode)
print('contrast\t\t', self.camera.contrast)
print('digital_gain\t\t', self.camera.digital_gain)
print('drc_strength\t\t', self.camera.drc_strength)
print('exposure_mode\t\t', self.camera.exposure_mode)
print('exposure_speed\t\t', self.camera.exposure_speed)
print('flash_mode\t\t', self.camera.flash_mode)
print('framerate\t\t', self.camera.framerate)
print('meter_mode\t\t', self.camera.meter_mode)
print('overlays\t\t', self.camera.overlays)
print('resolution\t\t', self.camera.resolution)
print('revision\t\t', self.camera.revision)
print('rotation\t\t', self.camera.rotation)
print('saturation\t\t', self.camera.saturation)
print('sensor_mode\t\t', self.camera.sensor_mode)
print('sharpness\t\t', self.camera.sharpness)
print('shutter_speed\t\t', self.camera.shutter_speed)
print('timestamp\t\t', self.camera.timestamp)
print('video_denoise\t\t', self.camera.video_denoise)
print('video_stabilization\t', self.camera.video_stabilization)
print('zoom\t\t\t', self.camera.zoom)