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 23ISO_EXP_TOL = 0.1 24NUM_TEST_ITERATIONS = 3 25 26 27def main(): 28 """Basic test for 3A consistency. 29 30 To pass, 3A must converge for exp, gain, awb, fd within TOL. 31 """ 32 33 with its.device.ItsSession() as cam: 34 props = cam.get_camera_properties() 35 its.caps.skip_unless(its.caps.read_3a(props)) 36 mono_camera = its.caps.mono_camera(props) 37 38 iso_exps = [] 39 g_gains = [] 40 fds = [] 41 for _ in range(NUM_TEST_ITERATIONS): 42 try: 43 s, e, gains, xform, fd = cam.do_3a(get_results=True, 44 mono_camera=mono_camera) 45 print ' iso: %d, exposure: %d, iso*exp: %d' % (s, e, e*s) 46 print ' awb_gains', gains, 'awb_transform', xform 47 print ' fd', fd 48 print '' 49 iso_exps.append(e*s) 50 g_gains.append(gains[2]) 51 fds.append(fd) 52 except its.error.Error: 53 print ' FAIL\n' 54 assert len(iso_exps) == NUM_TEST_ITERATIONS 55 assert np.isclose(np.amax(iso_exps), np.amin(iso_exps), ISO_EXP_TOL) 56 assert np.isclose(np.amax(g_gains), np.amin(g_gains), GGAIN_TOL) 57 assert np.isclose(np.amax(fds), np.amin(fds), FD_TOL) 58 for g in gains: 59 assert not np.isnan(g) 60 for x in xform: 61 assert not np.isnan(x) 62 63if __name__ == '__main__': 64 main() 65 66