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 os.path 16import its.caps 17import its.device 18import its.image 19import its.objects 20 21BURST_LEN = 8 22COLORS = ['R', 'G', 'B'] 23FPS_MAX_DIFF = 2.0 24NAME = os.path.basename(__file__).split('.')[0] 25SPREAD_THRESH_MANUAL_SENSOR = 0.01 26SPREAD_THRESH = 0.03 27VALUE_THRESH = 0.1 28 29 30def main(): 31 """Test 3A lock + YUV burst (using auto settings). 32 33 This is a test that is designed to pass even on limited devices that 34 don't have MANUAL_SENSOR or PER_FRAME_CONTROLS. The test checks 35 YUV image consistency while the frame rate check is in CTS. 36 """ 37 38 with its.device.ItsSession() as cam: 39 props = cam.get_camera_properties() 40 its.caps.skip_unless(its.caps.ae_lock(props) and 41 its.caps.awb_lock(props)) 42 mono_camera = its.caps.mono_camera(props) 43 44 # Converge 3A prior to capture. 45 cam.do_3a(do_af=True, lock_ae=True, lock_awb=True, 46 mono_camera=mono_camera) 47 48 fmt = its.objects.get_largest_yuv_format(props) 49 50 # After 3A has converged, lock AE+AWB for the duration of the test. 51 print 'Locking AE & AWB' 52 req = its.objects.fastest_auto_capture_request(props) 53 req['android.control.awbLock'] = True 54 req['android.control.aeLock'] = True 55 56 # Capture bursts of YUV shots. 57 # Get the mean values of a center patch for each. 58 r_means = [] 59 g_means = [] 60 b_means = [] 61 caps = cam.do_capture([req]*BURST_LEN, fmt) 62 for i, cap in enumerate(caps): 63 img = its.image.convert_capture_to_rgb_image(cap) 64 its.image.write_image(img, '%s_frame%d.jpg'%(NAME, i)) 65 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1) 66 means = its.image.compute_image_means(tile) 67 r_means.append(means[0]) 68 g_means.append(means[1]) 69 b_means.append(means[2]) 70 71 # Assert center patch brightness & similarity 72 for i, means in enumerate([r_means, g_means, b_means]): 73 plane = COLORS[i] 74 min_means = min(means) 75 spread = max(means) - min_means 76 print '%s patch mean spread %.5f. means = [' % (plane, spread), 77 for j in range(BURST_LEN): 78 print '%.5f' % means[j], 79 print ']' 80 e_msg = 'Image too dark! %s: %.5f, THRESH: %.2f' % ( 81 plane, min_means, VALUE_THRESH) 82 assert min_means > VALUE_THRESH, e_msg 83 threshold = SPREAD_THRESH_MANUAL_SENSOR \ 84 if its.caps.manual_sensor(props) else SPREAD_THRESH 85 e_msg = '%s center patch spread: %.5f, THRESH: %.2f' % ( 86 plane, spread, threshold) 87 assert spread < threshold, e_msg 88 89if __name__ == '__main__': 90 main() 91 92