test_latching.py revision 4902d71d230d21639be817a83e8998230a6ff5e0
1# Copyright 2013 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import its.image
16import its.device
17import its.objects
18import pylab
19import os.path
20import matplotlib
21import matplotlib.pyplot
22import copy
23
24def main():
25    """Test that settings latch on the right frame.
26
27    Takes a bunch of shots using back-to-back requests, varying the capture
28    request parameters between shots. Checks that the images that come back
29    have the expexted properties.
30    """
31    NAME = os.path.basename(__file__).split(".")[0]
32
33    S = 150 # Sensitivity
34    E = 10 # Exposure time, ms
35
36    reqs = [
37        its.objects.manual_capture_request(S,  E  ),
38        its.objects.manual_capture_request(S,  E  ),
39        its.objects.manual_capture_request(S*8,E  ),
40        its.objects.manual_capture_request(S*8,E  ),
41        its.objects.manual_capture_request(S,  E  ),
42        its.objects.manual_capture_request(S,  E  ),
43        its.objects.manual_capture_request(S,  E*8),
44        its.objects.manual_capture_request(S,  E  ),
45        its.objects.manual_capture_request(S*8,E  ),
46        its.objects.manual_capture_request(S,  E  ),
47        its.objects.manual_capture_request(S,  E*8),
48        its.objects.manual_capture_request(S,  E  ),
49        ]
50
51    r_means = []
52    g_means = []
53    b_means = []
54
55    with its.device.ItsSession() as cam:
56        fnames, w, h, cap_mds = cam.do_capture(reqs)
57        for i, fname in enumerate(fnames):
58            img = its.image.load_yuv420_to_rgb_image(fname, w, h)
59            its.image.write_image(img, "%s_i=%02d.jpg" % (NAME, i))
60            tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
61            rgb_means = its.image.compute_image_means(tile)
62            r_means.append(rgb_means[0])
63            g_means.append(rgb_means[1])
64            b_means.append(rgb_means[2])
65
66    # Draw a plot.
67    idxs = range(len(r_means))
68    pylab.plot(idxs, r_means, 'r')
69    pylab.plot(idxs, g_means, 'g')
70    pylab.plot(idxs, b_means, 'b')
71    pylab.ylim([0,1])
72    matplotlib.pyplot.savefig("%s_plot_means.png" % (NAME))
73
74if __name__ == '__main__':
75    main()
76
77