test_black_white.py revision 87b68b020dd72c4cdcf3b8c1f9196c060f947991
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 sys
19import numpy
20import Image
21import pprint
22import math
23import pylab
24import os.path
25import matplotlib
26import matplotlib.pyplot
27
28def main():
29    """Test that the device will produce full black+white images.
30    """
31    NAME = os.path.basename(__file__).split(".")[0]
32
33    req = its.objects.capture_request( {
34        "android.sensor.exposureTime": 10*1000, # 0.01ms
35        "android.sensor.sensitivity": 100,
36        "android.sensor.frameDuration": 0,
37        "android.control.mode": 0,
38        "android.control.aeMode": 0,
39        "android.control.awbMode": 0,
40        "android.control.afMode": 0,
41        "android.control.effectMode": 0,
42        })
43
44    with its.device.ItsSession() as cam:
45        # Take a shot with very low ISO and exposure time. Expect it to
46        # be black.
47        fname, w, h, cap_md = cam.do_capture(req)
48        img = its.image.load_yuv420_to_rgb_image(fname, w, h)
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        print "Dark pixel means:", black_means
53
54        # Take a shot with very high ISO and exposure time. Expect it to
55        # be black.
56        req["captureRequest"]["android.sensor.sensitivity"] = 10000
57        req["captureRequest"]["android.sensor.exposureTime"] = 1000*1000*1000
58        fname, w, h, cap_md = cam.do_capture(req)
59        img = its.image.load_yuv420_to_rgb_image(fname, w, h)
60        its.image.write_image(img, "%s_white.jpg" % (NAME))
61        tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
62        white_means = its.image.compute_image_means(tile)
63        print "Bright pixel means:", white_means
64
65        for val in black_means:
66            assert(val < 0.025)
67        for val in white_means:
68            assert(val > 0.975)
69
70if __name__ == '__main__':
71    main()
72
73