-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbrightData.py
110 lines (91 loc) · 2.97 KB
/
brightData.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
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
99
100
101
102
103
104
105
106
107
108
109
110
import Image
import subprocess
import random
import os, sys, getopt
usagestring="Usage: brightData.py [options]\n"
usagestring+="Options:\n"
usagestring+="-q : Print this usage screen.\n"
usagestring+="-n : Number of shots to take. Best not to mix with manual ss/iso.\n"
usagestring+="-s 5000 : Manually set shutter speed.\n"
usagestring+="-o 100 : Manually set ISO.\n"
def argassign(arg, typ='int'):
#Assign integer arg to variable, or quit if it fails.
try:
if typ=='float':
return float(arg)
elif typ=='int':
return int(arg)
else:
return str(arg)
except:
print usagestring
sys.exit(2)
return False
def main(argv):
w=str(64)
h=str(48)
initialss=10000
initialiso=100
miniso=100
maxiso=800
minss=100
maxss=350000
ss=None
iso=None
nshots=1
try:
opts, args = getopt.getopt(argv,"qn:s:o:", [])
except getopt.GetoptError:
print usagestring
sys.exit(2)
for opt, arg in opts:
if opt == '-q':
print usagestring
sys.exit()
elif opt=="-n":
nshots=argassign(arg,'int')
elif opt=="-s":
ss=argassign(arg,'int')
elif opt=="-o":
iso=argassign(arg,'int')
if ss==None: ss=random.randint(minss, maxss)
if iso==None: iso=random.randint(miniso, maxiso)
f=open('/etc/hostname')
hostname=f.read().strip().replace(' ','')
f.close()
if not os.path.exists("/home/pi/brdata")
os.mkdir('/home/pi/brdata/')
for i in range(nshots):
dtime=subprocess.check_output(['date', '+%y%m%d_%T']).strip()
dtime=dtime.replace(':', '.')
filename1='/home/pi/brdata/'+hostname+'_'+dtime+'_'+'base.jpg'
filename2='/home/pi/brdata/'+hostname+'_'+dtime+'_'+str(ss)+'_'+str(iso)+'.jpg'
#Take the picture with base ss and iso.
options='-hf -vf -awb off -n'
options+=' -w '+w+' -h '+h
options+=' -t 100'
options+=' -ss '+str(initialss)
options+=' -ISO '+str(initialiso)
options+=' -o new.jpg'
subprocess.call('raspistill '+options, shell=True)
im1=Image.open('new.jpg')
#Take the picture with new ss and iso.
options='-hf -vf -awb off -n'
options+=' -w '+w+' -h '+h
options+=' -t 100'
options+=' -ss '+str(ss)
options+=' -ISO '+str(iso)
options+=' -o new.jpg'
subprocess.call('raspistill '+options, shell=True)
im2=Image.open('new.jpg')
histogram=im2.convert('L').histogram()
#Ignore mostly-black and mostly-white images.
if histogram[0]<64*16 and histogram[-1]<64*16:
im1.save(filename1)
im2.save(filename2)
ss=random.randint(minss, maxss)
iso=random.randint(miniso, maxiso)
return True
#-------------------------------------------------------------------------------
if __name__ == "__main__":
main(sys.argv[1:])