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