aboutsummaryrefslogtreecommitdiff
path: root/apps/CameraITS/tests/scene1/test_tonemap_sequence.py
blob: 4f519cb16e6a8d1c3e19ab338e3ab1baff74a46f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import its.image
import its.device
import its.objects
import os.path
import numpy

def main():
    """Test a sequence of shots with different tonemap curves.
    """
    NAME = os.path.basename(__file__).split(".")[0]

    # There should be 3 identical frames followed by a different set of
    # 3 identical frames.
    MAX_SAME_DELTA = 0.01
    MIN_DIFF_DELTA = 0.10

    with its.device.ItsSession() as cam:
        sens, exp_time, _,_,_ = cam.do_3a(do_af=False)

        means = []

        # Capture 3 manual shots with a linear tonemap.
        req = its.objects.manual_capture_request(sens, exp_time, True)
        for i in [0,1,2]:
            cap = cam.do_capture(req)
            img = its.image.convert_capture_to_rgb_image(cap)
            its.image.write_image(img, "%s_i=%d.jpg" % (NAME, i))
            tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
            means.append(tile.mean(0).mean(0))

        # Capture 3 manual shots with the default tonemap.
        req = its.objects.manual_capture_request(sens, exp_time, False)
        for i in [3,4,5]:
            cap = cam.do_capture(req)
            img = its.image.convert_capture_to_rgb_image(cap)
            its.image.write_image(img, "%s_i=%d.jpg" % (NAME, i))
            tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
            means.append(tile.mean(0).mean(0))

        # Compute the delta between each consecutive frame pair.
        deltas = [numpy.max(numpy.fabs(means[i+1]-means[i])) \
                  for i in range(len(means)-1)]
        print "Deltas between consecutive frames:", deltas

        assert(all([abs(deltas[i]) < MAX_SAME_DELTA for i in [0,1,3,4]]))
        assert(abs(deltas[2]) > MIN_DIFF_DELTA)

if __name__ == '__main__':
    main()