• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 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.caps
16import its.device
17import its.target
18
19import numpy as np
20
21GGAIN_TOL = 0.1
22FD_TOL = 0.1
23SENS_TOL = 0.1
24EXP_TOL = 0.1
25NUM_TEST_ITERATIONS = 3
26
27
28def main():
29    """Basic test for 3A consistency.
30
31    To pass, 3A must converge for exp, gain, awb, fd within TOL.
32    """
33
34    with its.device.ItsSession() as cam:
35        props = cam.get_camera_properties()
36        its.caps.skip_unless(its.caps.read_3a(props))
37        mono_camera = its.caps.mono_camera(props)
38
39        exps = []
40        senses = []
41        g_gains = []
42        fds = []
43        for _ in range(NUM_TEST_ITERATIONS):
44            try:
45                s, e, gains, xform, fd = cam.do_3a(get_results=True,
46                                                   mono_camera=mono_camera)
47                print ' sensitivity', s, 'exposure', e
48                print ' gains', gains, 'transform', xform
49                print ' fd', fd
50                print ''
51                exps.append(e)
52                senses.append(s)
53                g_gains.append(gains[2])
54                fds.append(fd)
55            except its.error.Error:
56                print ' FAIL\n'
57        assert len(exps) == NUM_TEST_ITERATIONS
58        assert np.isclose(np.amax(exps), np.amin(exps), EXP_TOL)
59        assert np.isclose(np.amax(senses), np.amin(senses), SENS_TOL)
60        assert np.isclose(np.amax(g_gains), np.amin(g_gains), GGAIN_TOL)
61        assert np.isclose(np.amax(fds), np.amin(fds), FD_TOL)
62        for g in gains:
63            assert not np.isnan(g)
64        for x in xform:
65            assert not np.isnan(x)
66
67if __name__ == '__main__':
68    main()
69
70