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.005 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 # After 3A has converged, lock AE+AWB for the duration of the test. 48 req = its.objects.fastest_auto_capture_request(props) 49 req["android.control.awbLock"] = True 50 req["android.control.aeLock"] = True 51 52 # Capture bursts of YUV shots. 53 # Get the mean values of a center patch for each. 54 r_means = [] 55 g_means = [] 56 b_means = [] 57 caps = cam.do_capture([req]*BURST_LEN) 58 for i,cap in enumerate(caps): 59 img = its.image.convert_capture_to_rgb_image(cap) 60 its.image.write_image(img, "%s_frame%d.jpg"%(NAME,i)) 61 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1) 62 means = its.image.compute_image_means(tile) 63 r_means.append(means[0]) 64 g_means.append(means[1]) 65 b_means.append(means[2]) 66 67 # Pass/fail based on center patch similarity. 68 for means in [r_means, g_means, b_means]: 69 spread = max(means) - min(means) 70 print "Patch mean spread", spread, \ 71 " (min/max: ", min(means), "/", max(means), ")" 72 threshold = SPREAD_THRESH_MANUAL_SENSOR \ 73 if its.caps.manual_sensor(props) else SPREAD_THRESH 74 assert(spread < threshold) 75 76if __name__ == '__main__': 77 main() 78 79