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
|
# Copyright 2013 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import its.image
import its.device
import its.objects
import pylab
import os.path
import matplotlib
import matplotlib.pyplot
def main():
"""Test that BLC and LSC look reasonable.
"""
NAME = os.path.basename(__file__).split(".")[0]
r_means_center = []
g_means_center = []
b_means_center = []
r_means_corner = []
g_means_corner = []
b_means_corner = []
with its.device.ItsSession() as cam:
props = cam.get_camera_properties()
expt_range = props['android.sensor.info.exposureTimeRange']
# Get AE+AWB lock first, so the auto values in the capture result are
# populated properly.
r = [[0,0,1,1,1]]
ae_sen,ae_exp,awb_gains,awb_transform,_ = \
cam.do_3a(r,r,r,True,True,False)
print "AE:", ae_sen, ae_exp / 1000000.0
print "AWB:", awb_gains, awb_transform
# Set analog gain (sensitivity) to 800
ae_exp = ae_exp * ae_sen / 800
ae_sen = 800
# Capture range of exposures from 1/100x to 4x of AE estimate.
exposures = [ae_exp*x/100.0 for x in [1]+range(10,401,40)]
exposures = [e for e in exposures
if e >= expt_range[0] and e <= expt_range[1]]
# Convert the transform back to rational.
awb_transform_rat = its.objects.float_to_rational(awb_transform)
# Linear tonemap
tmap = sum([[i/63.0,i/63.0] for i in range(64)], [])
reqs = []
for e in exposures:
req = its.objects.manual_capture_request(ae_sen,e)
req["android.tonemap.mode"] = 0
req["android.tonemap.curveRed"] = tmap
req["android.tonemap.curveGreen"] = tmap
req["android.tonemap.curveBlue"] = tmap
req["android.colorCorrection.transform"] = awb_transform_rat
req["android.colorCorrection.gains"] = awb_gains
reqs.append(req)
caps = cam.do_capture(reqs)
for i,cap in enumerate(caps):
img = its.image.convert_capture_to_rgb_image(cap)
its.image.write_image(img, "%s_i=%d.jpg"%(NAME, i))
tile_center = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
rgb_means = its.image.compute_image_means(tile_center)
r_means_center.append(rgb_means[0])
g_means_center.append(rgb_means[1])
b_means_center.append(rgb_means[2])
tile_corner = its.image.get_image_patch(img, 0.0, 0.0, 0.1, 0.1)
rgb_means = its.image.compute_image_means(tile_corner)
r_means_corner.append(rgb_means[0])
g_means_corner.append(rgb_means[1])
b_means_corner.append(rgb_means[2])
fig = matplotlib.pyplot.figure()
pylab.plot(exposures, r_means_center, 'r')
pylab.plot(exposures, g_means_center, 'g')
pylab.plot(exposures, b_means_center, 'b')
pylab.ylim([0,1])
matplotlib.pyplot.savefig("%s_plot_means_center.png" % (NAME))
fig = matplotlib.pyplot.figure()
pylab.plot(exposures, r_means_corner, 'r')
pylab.plot(exposures, g_means_corner, 'g')
pylab.plot(exposures, b_means_corner, 'b')
pylab.ylim([0,1])
matplotlib.pyplot.savefig("%s_plot_means_corner.png" % (NAME))
if __name__ == '__main__':
main()
|