-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_camera.py
More file actions
84 lines (68 loc) · 2.41 KB
/
test_camera.py
File metadata and controls
84 lines (68 loc) · 2.41 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
import time
import os
import errno
import sys
import threading
import picamera
import gps
gpsd=None
class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
global gpsd #bring it in scope
gpsd = gps.gps(mode=gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE) #starting the stream of info
self.current_value = None
self.running = True #setting the thread running to true
def run(self):
global gpsd
while gpsp.running:
gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
gpsd=None
if __name__ == '__main__':
print 'starting GPS'
gpsp = GpsPoller()
gpsp.start()
path = '/home/pi/camera/output'
print 'make output directory'
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
print 'starting camera'
with picamera.PiCamera() as camera:
camera.resolution = (2592, 1944)
print 'waiting to power up'
time.sleep(1)
camera.exposure_mode = 'sports'
while True:
#read a GPS location
try:
lat_lng_string = "%s,%s" % (gpsd.fix.latitude, gpsd.fix.longitude)
except AttributeError:
lat_lng_string = "no gps fix"
except KeyError:
lat_lng_string = "no gps fix"
except StopIteration:
session = None
lat_lng_string = "GPSD has terminated"
#Take a picture
try:
timestr = time.strftime("%Y%m%d-%H%M%S")
if camera.exposure_mode == 'sports':
camera.exposure_mode = 'auto'
else:
camera.exposure_mode = 'sports'
filename = '%s.jpg' % (timestr)
camera.capture(os.path.join(path, filename))
print '%s,%s,%s' % (filename, lat_lng_string, camera.exposure_mode)
sys.stdout.flush()
#Stop if we have less than 100MB
st = os.statvfs(path)
free_meg = st.f_bavail * st.f_frsize / 2**20
if free_meg < 100:
break
time.sleep(30)
except picamera.exc.PiCameraRuntimeError as exception:
print 'encountered exception %s' % str(exception)
print 'done'