• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 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 os.path
20import numpy
21
22def main():
23    """Test a sequence of shots with different tonemap curves.
24    """
25    NAME = os.path.basename(__file__).split(".")[0]
26
27    # There should be 3 identical frames followed by a different set of
28    # 3 identical frames.
29    MAX_SAME_DELTA = 0.03  # match number in test_burst_sameness_manual
30    MIN_DIFF_DELTA = 0.10
31
32    with its.device.ItsSession() as cam:
33        props = cam.get_camera_properties()
34        its.caps.skip_unless(its.caps.manual_sensor(props) and
35                             its.caps.manual_post_proc(props) and
36                             its.caps.per_frame_control(props) and
37                             not its.caps.mono_camera(props))
38
39        debug = its.caps.debug_mode()
40        largest_yuv = its.objects.get_largest_yuv_format(props)
41        if debug:
42            fmt = largest_yuv
43        else:
44            match_ar = (largest_yuv['width'], largest_yuv['height'])
45            fmt = its.objects.get_smallest_yuv_format(props, match_ar=match_ar)
46
47        sens, exp_time, _,_,f_dist = cam.do_3a(do_af=True,get_results=True)
48
49        means = []
50
51        # Capture 3 manual shots with a linear tonemap.
52        req = its.objects.manual_capture_request(sens, exp_time, f_dist, True, props)
53        for i in [0,1,2]:
54            cap = cam.do_capture(req, fmt)
55            img = its.image.convert_capture_to_rgb_image(cap)
56            its.image.write_image(img, "%s_i=%d.jpg" % (NAME, i))
57            tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
58            means.append(tile.mean(0).mean(0))
59
60        # Capture 3 manual shots with the default tonemap.
61        req = its.objects.manual_capture_request(sens, exp_time, f_dist, False)
62        for i in [3,4,5]:
63            cap = cam.do_capture(req, fmt)
64            img = its.image.convert_capture_to_rgb_image(cap)
65            its.image.write_image(img, "%s_i=%d.jpg" % (NAME, i))
66            tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
67            means.append(tile.mean(0).mean(0))
68
69        # Compute the delta between each consecutive frame pair.
70        deltas = [numpy.max(numpy.fabs(means[i+1]-means[i])) \
71                  for i in range(len(means)-1)]
72        print "Deltas between consecutive frames:", deltas
73
74        assert(all([abs(deltas[i]) < MAX_SAME_DELTA for i in [0,1,3,4]]))
75        assert(abs(deltas[2]) > MIN_DIFF_DELTA)
76
77if __name__ == '__main__':
78    main()
79
80