1# Copyright 2013 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.caps 17import its.device 18import its.objects 19import its.target 20from matplotlib import pylab 21import os.path 22import matplotlib 23import matplotlib.pyplot 24 25def main(): 26 """Test that the android.sensor.exposureTime parameter is applied. 27 """ 28 NAME = os.path.basename(__file__).split(".")[0] 29 30 exp_times = [] 31 r_means = [] 32 g_means = [] 33 b_means = [] 34 35 with its.device.ItsSession() as cam: 36 props = cam.get_camera_properties() 37 its.caps.skip_unless(its.caps.compute_target_exposure(props) and 38 its.caps.per_frame_control(props)) 39 40 debug = its.caps.debug_mode() 41 largest_yuv = its.objects.get_largest_yuv_format(props) 42 if debug: 43 fmt = largest_yuv 44 else: 45 match_ar = (largest_yuv['width'], largest_yuv['height']) 46 fmt = its.objects.get_smallest_yuv_format(props, match_ar=match_ar) 47 48 e,s = its.target.get_target_exposure_combos(cam)["midExposureTime"] 49 for i,e_mult in enumerate([0.8, 0.9, 1.0, 1.1, 1.2]): 50 req = its.objects.manual_capture_request(s, e * e_mult, 0.0, True, props) 51 cap = cam.do_capture(req, fmt) 52 img = its.image.convert_capture_to_rgb_image(cap) 53 its.image.write_image( 54 img, "%s_frame%d.jpg" % (NAME, i)) 55 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1) 56 rgb_means = its.image.compute_image_means(tile) 57 exp_times.append(e * e_mult) 58 r_means.append(rgb_means[0]) 59 g_means.append(rgb_means[1]) 60 b_means.append(rgb_means[2]) 61 62 # Draw a plot. 63 pylab.plot(exp_times, r_means, 'r') 64 pylab.plot(exp_times, g_means, 'g') 65 pylab.plot(exp_times, b_means, 'b') 66 pylab.ylim([0,1]) 67 matplotlib.pyplot.savefig("%s_plot_means.png" % (NAME)) 68 69 # Test for pass/fail: check that each shot is brighter than the previous. 70 for means in [r_means, g_means, b_means]: 71 for i in range(len(means)-1): 72 assert(means[i+1] > means[i]) 73 74if __name__ == '__main__': 75 main() 76 77