• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.caps
17import its.device
18import its.objects
19import pylab
20import os.path
21import matplotlib
22import matplotlib.pyplot
23
24def main():
25    """Test that the device will produce full black+white images.
26    """
27    NAME = os.path.basename(__file__).split(".")[0]
28
29    r_means = []
30    g_means = []
31    b_means = []
32
33    with its.device.ItsSession() as cam:
34        props = cam.get_camera_properties()
35        if not its.caps.manual_sensor(props):
36            print "Test skipped"
37            return
38
39        expt_range = props['android.sensor.info.exposureTimeRange']
40        sens_range = props['android.sensor.info.sensitivityRange']
41
42        # Take a shot with very low ISO and exposure time. Expect it to
43        # be black.
44        print "Black shot: sens = %d, exp time = %.4fms" % (
45                sens_range[0], expt_range[0]/1000000.0)
46        req = its.objects.manual_capture_request(sens_range[0], expt_range[0])
47        cap = cam.do_capture(req)
48        img = its.image.convert_capture_to_rgb_image(cap)
49        its.image.write_image(img, "%s_black.jpg" % (NAME))
50        tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
51        black_means = its.image.compute_image_means(tile)
52        r_means.append(black_means[0])
53        g_means.append(black_means[1])
54        b_means.append(black_means[2])
55        print "Dark pixel means:", black_means
56
57        # Take a shot with very high ISO and exposure time. Expect it to
58        # be white.
59        print "White shot: sens = %d, exp time = %.2fms" % (
60                sens_range[1], expt_range[1]/1000000.0)
61        req = its.objects.manual_capture_request(sens_range[1], expt_range[1])
62        cap = cam.do_capture(req)
63        img = its.image.convert_capture_to_rgb_image(cap)
64        its.image.write_image(img, "%s_white.jpg" % (NAME))
65        tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
66        white_means = its.image.compute_image_means(tile)
67        r_means.append(white_means[0])
68        g_means.append(white_means[1])
69        b_means.append(white_means[2])
70        print "Bright pixel means:", white_means
71
72        # Draw a plot.
73        pylab.plot([0,1], r_means, 'r')
74        pylab.plot([0,1], g_means, 'g')
75        pylab.plot([0,1], b_means, 'b')
76        pylab.ylim([0,1])
77        matplotlib.pyplot.savefig("%s_plot_means.png" % (NAME))
78
79        for val in black_means:
80            assert(val < 0.025)
81        for val in white_means:
82            assert(val > 0.975)
83
84if __name__ == '__main__':
85    main()
86
87