• 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.01
30    MIN_DIFF_DELTA = 0.10
31
32    with its.device.ItsSession() as cam:
33        props = cam.get_camera_properties()
34        if (not its.caps.manual_sensor(props) or
35            not its.caps.manual_post_proc(props)):
36            print "Test skipped"
37            return
38
39        sens, exp_time, _,_,_ = cam.do_3a(do_af=False,get_results=True)
40
41        means = []
42
43        # Capture 3 manual shots with a linear tonemap.
44        req = its.objects.manual_capture_request(sens, exp_time, True)
45        for i in [0,1,2]:
46            cap = cam.do_capture(req)
47            img = its.image.convert_capture_to_rgb_image(cap)
48            its.image.write_image(img, "%s_i=%d.jpg" % (NAME, i))
49            tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
50            means.append(tile.mean(0).mean(0))
51
52        # Capture 3 manual shots with the default tonemap.
53        req = its.objects.manual_capture_request(sens, exp_time, False)
54        for i in [3,4,5]:
55            cap = cam.do_capture(req)
56            img = its.image.convert_capture_to_rgb_image(cap)
57            its.image.write_image(img, "%s_i=%d.jpg" % (NAME, i))
58            tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
59            means.append(tile.mean(0).mean(0))
60
61        # Compute the delta between each consecutive frame pair.
62        deltas = [numpy.max(numpy.fabs(means[i+1]-means[i])) \
63                  for i in range(len(means)-1)]
64        print "Deltas between consecutive frames:", deltas
65
66        assert(all([abs(deltas[i]) < MAX_SAME_DELTA for i in [0,1,3,4]]))
67        assert(abs(deltas[2]) > MIN_DIFF_DELTA)
68
69if __name__ == '__main__':
70    main()
71
72