-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestSuite_WhiteBalanceTest.py
185 lines (174 loc) · 6.71 KB
/
TestSuite_WhiteBalanceTest.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# This is a simple script that will take a set of photos to show you what each White Balance setting looks like.
#
# Licence: GPLv3 see here: http://www.gnu.org/licenses/gpl.html
# By Daniel Scott - 2015
# www.likecrashingwaves.com
import time
import picamera
import uuid
import os
# Declare whether you want to use annotations saying what white balance
# the shot used. It'll be printed on the actual image if its set to 1
# or higher, but nothing will print if its set to 0.
annotations = 0
# How many test shots of each white balance setting do you want to take?
shots = 3
# Set the width of the photo.
shotwidth = 1280
# Set the height of the photo.
shotheight = 720
# Set the save location of your images
path = '/home/pi/pypicamera/'
with picamera.PiCamera() as camera:
camera.resolution = (shotwidth, shotheight)
camera.framerate = 30
# Wait for the automatic gain control to settle
time.sleep(2)
# Now fix the values
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'sunlight'
if annotations > 0:
camera.annotate_text = 'White Balance: Sunlight'
# camera.awb_gains = g
filename = ('sunlight%02d{u}.jpg'.format(u=uuid.uuid4()))
fullpath = os.path.join(path, filename)
# Finally, take several photos with the fixed settings
camera.capture_sequence(fullpath % i for i in range(shots))
with picamera.PiCamera() as camera:
camera.resolution = (shotwidth, shotheight)
camera.framerate = 30
# Wait for the automatic gain control to settle
time.sleep(2)
# Now fix the values
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'auto'
if annotations > 0:
camera.annotate_text = 'White Balance: Auto'
# camera.awb_gains = g
filename = ('auto%02d{u}.jpg'.format(u=uuid.uuid4()))
fullpath = os.path.join(path, filename)
# Finally, take several photos with the fixed settings
camera.capture_sequence(fullpath % i for i in range(shots))
with picamera.PiCamera() as camera:
camera.resolution = (shotwidth, shotheight)
camera.framerate = 30
# Wait for the automatic gain control to settle
time.sleep(2)
# Now fix the values
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'cloudy'
if annotations > 0:
camera.annotate_text = 'White Balance: Cloudy'
# camera.awb_gains = g
filename = ('cloudy%02d{u}.jpg'.format(u=uuid.uuid4()))
fullpath = os.path.join(path, filename)
# Finally, take several photos with the fixed settings
camera.capture_sequence(fullpath % i for i in range(shots))
with picamera.PiCamera() as camera:
camera.resolution = (shotwidth, shotheight)
camera.framerate = 30
# Wait for the automatic gain control to settle
time.sleep(2)
# Now fix the values
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'shade'
if annotations > 0:
camera.annotate_text = 'White Balance: Shade'
# camera.awb_gains = g
filename = ('shade%02d{u}.jpg'.format(u=uuid.uuid4()))
fullpath = os.path.join(path, filename)
# Finally, take several photos with the fixed settings
camera.capture_sequence(fullpath % i for i in range(shots))
with picamera.PiCamera() as camera:
camera.resolution = (shotwidth, shotheight)
camera.framerate = 30
# Wait for the automatic gain control to settle
time.sleep(2)
# Now fix the values
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'tungsten'
if annotations > 0:
camera.annotate_text = 'White Balance: Tungsten'
# camera.awb_gains = g
filename = ('tungsten%02d{u}.jpg'.format(u=uuid.uuid4()))
fullpath = os.path.join(path, filename)
# Finally, take several photos with the fixed settings
camera.capture_sequence(fullpath % i for i in range(shots))
with picamera.PiCamera() as camera:
camera.resolution = (shotwidth, shotheight)
camera.framerate = 30
# Wait for the automatic gain control to settle
time.sleep(2)
# Now fix the values
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'fluorescent'
if annotations > 0:
camera.annotate_text = 'White Balance: Fluorescent'
# camera.awb_gains = g
filename = ('fluorescent%02d{u}.jpg'.format(u=uuid.uuid4()))
fullpath = os.path.join(path, filename)
# Finally, take several photos with the fixed settings
camera.capture_sequence(fullpath % i for i in range(shots))
with picamera.PiCamera() as camera:
camera.resolution = (shotwidth, shotheight)
camera.framerate = 30
# Wait for the automatic gain control to settle
time.sleep(2)
# Now fix the values
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'incandescent'
if annotations > 0:
camera.annotate_text = 'White Balance: Incandescent'
# camera.awb_gains = g
filename = ('incandescent%02d{u}.jpg'.format(u=uuid.uuid4()))
fullpath = os.path.join(path, filename)
# Finally, take several photos with the fixed settings
camera.capture_sequence(fullpath % i for i in range(shots))
with picamera.PiCamera() as camera:
camera.resolution = (shotwidth, shotheight)
camera.framerate = 30
# Wait for the automatic gain control to settle
time.sleep(2)
# Now fix the values
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'flash'
if annotations > 0:
camera.annotate_text = 'White Balance: Flash'
# camera.awb_gains = g
filename = ('flash%02d{u}.jpg'.format(u=uuid.uuid4()))
fullpath = os.path.join(path, filename)
# Finally, take several photos with the fixed settings
camera.capture_sequence(fullpath % i for i in range(shots))
with picamera.PiCamera() as camera:
camera.resolution = (shotwidth, shotheight)
camera.framerate = 30
# Wait for the automatic gain control to settle
time.sleep(2)
# Now fix the values
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'horizon'
if annotations > 0:
camera.annotate_text = 'White Balance: Horizon'
# camera.awb_gains = g
filename = ('horizon%02d{u}.jpg'.format(u=uuid.uuid4()))
fullpath = os.path.join(path, filename)
# Finally, take several photos with the fixed settings
camera.capture_sequence(fullpath % i for i in range(shots))