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"""Verifies YUV image consistency with AE and AWB locked.""" 15 16 17import logging 18import os.path 19from mobly import test_runner 20 21import its_base_test 22import camera_properties_utils 23import capture_request_utils 24import image_processing_utils 25import its_session_utils 26 27_BURST_LEN = 8 28_COLORS = ('R', 'G', 'B') 29_FPS_MAX_DIFF = 2.0 30_NAME = os.path.splitext(os.path.basename(__file__))[0] 31_PATCH_H = 0.1 # center 10% 32_PATCH_W = 0.1 33_PATCH_X = 0.5 - _PATCH_W/2 34_PATCH_Y = 0.5 - _PATCH_H/2 35_SPREAD_THRESH_MANUAL_SENSOR = 0.01 36_SPREAD_THRESH = 0.03 37_VALUE_THRESH = 0.1 38 39 40class LockedBurstTest(its_base_test.ItsBaseTest): 41 """Test 3A lock + YUV burst (using auto settings). 42 43 This is a test designed to pass even on limited devices that 44 don't have MANUAL_SENSOR or PER_FRAME_CONTROL. The test checks 45 YUV image consistency while the frame rate check is in CTS. 46 """ 47 48 def test_locked_burst(self): 49 logging.debug('Starting %s', _NAME) 50 with its_session_utils.ItsSession( 51 device_id=self.dut.serial, 52 camera_id=self.camera_id, 53 hidden_physical_id=self.hidden_physical_id) as cam: 54 props = cam.get_camera_properties() 55 props = cam.override_with_hidden_physical_camera_props(props) 56 mono_camera = camera_properties_utils.mono_camera(props) 57 log_path = self.log_path 58 59 # check SKIP conditions 60 camera_properties_utils.skip_unless( 61 camera_properties_utils.ae_lock(props) and 62 camera_properties_utils.awb_lock(props)) 63 64 # Load chart for scene 65 its_session_utils.load_scene( 66 cam, props, self.scene, self.tablet, self.chart_distance) 67 68 # Converge 3A prior to capture. 69 camera_properties_utils.log_minimum_focus_distance(props) 70 71 fmt = capture_request_utils.get_largest_format('yuv', props) 72 cam.do_3a(do_af=True, lock_ae=True, lock_awb=True, 73 mono_camera=mono_camera, out_surfaces=fmt) 74 75 # After 3A has converged, lock AE+AWB for the duration of the test. 76 logging.debug('Locking AE & AWB') 77 req = capture_request_utils.fastest_auto_capture_request(props) 78 req['android.control.awbLock'] = True 79 req['android.control.aeLock'] = True 80 81 # Capture bursts of YUV shots. 82 # Get the mean values of a center patch for each. 83 r_means = [] 84 g_means = [] 85 b_means = [] 86 caps = cam.do_capture([req]*_BURST_LEN, fmt, reuse_session=True) 87 name_with_log_path = os.path.join(log_path, _NAME) 88 for i, cap in enumerate(caps): 89 img = image_processing_utils.convert_capture_to_rgb_image(cap) 90 image_processing_utils.write_image( 91 img, f'{name_with_log_path}_frame{i}.jpg') 92 patch = image_processing_utils.get_image_patch( 93 img, _PATCH_X, _PATCH_Y, _PATCH_W, _PATCH_H) 94 means = image_processing_utils.compute_image_means(patch) 95 r_means.append(means[0]) 96 g_means.append(means[1]) 97 b_means.append(means[2]) 98 99 # Assert center patch brightness & similarity 100 for i, means in enumerate([r_means, g_means, b_means]): 101 plane = _COLORS[i] 102 min_means = min(means) 103 spread = max(means) - min_means 104 logging.debug('%s patch mean spread %.5f. means = %s', 105 plane, spread, str(means)) 106 if min_means <= _VALUE_THRESH: 107 raise AssertionError(f'{plane} too dark! mean: ' 108 f'{min_means:.5f}, THRESH: {_VALUE_THRESH}') 109 threshold = _SPREAD_THRESH 110 if camera_properties_utils.manual_sensor(props): 111 threshold = _SPREAD_THRESH_MANUAL_SENSOR 112 if spread >= threshold: 113 raise AssertionError(f'{plane} center patch spread: {spread:.5f}, ' 114 f'THRESH: {threshold:.2f}') 115 116if __name__ == '__main__': 117 test_runner.main() 118 119