test_param_exposure_time.py revision 12339cdd90b2c98eb4f7adf794ddca8de53992b8
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
22
23def main():
24    """Test that the android.sensor.exposureTime parameter is applied.
25    """
26    NAME = os.path.basename(__file__).split(".")[0]
27
28    req = its.objects.capture_request( {
29        "android.control.mode": 0,
30        "android.control.aeMode": 0,
31        "android.control.aeLock": False,
32        "android.sensor.frameDuration": 0,
33        "android.sensor.sensitivity": 100
34        })
35
36    exposures = range(20,120,20) # ms
37    r_means = []
38    g_means = []
39    b_means = []
40
41    with its.device.ItsSession() as cam:
42        for e in exposures:
43            req["captureRequest"]["android.sensor.exposureTime"] = e*1000*1000
44            fname, w, h, cap_md = cam.do_capture(req)
45            img = its.image.load_yuv420_to_rgb_image(fname, w, h)
46            its.image.write_image(
47                    img, "%s_time=%03dms.jpg" % (NAME, e))
48            tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
49            rgb_means = its.image.compute_image_means(tile)
50            r_means.append(rgb_means[0])
51            g_means.append(rgb_means[1])
52            b_means.append(rgb_means[2])
53
54    # Draw a plot.
55    pylab.plot(exposures, r_means, 'r')
56    pylab.plot(exposures, g_means, 'g')
57    pylab.plot(exposures, b_means, 'b')
58    matplotlib.pyplot.savefig("%s_plot_means.png" % (NAME))
59
60if __name__ == '__main__':
61    main()
62
63