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 15 import its.image 16 import its.device 17 import its.objects 18 import its.target 19 import pylab 20 import os.path 21 import matplotlib 22 import matplotlib.pyplot 23 24 def main(): 25 """Test that the android.sensor.sensitivity parameter is applied. 26 """ 27 NAME = os.path.basename(__file__).split(".")[0] 28 29 # Pass/fail threshold. 30 THRESHOLD_MIN_DIFF = 0.02 31 32 NUM_STEPS = 5 33 34 sensitivities = None 35 r_means = [] 36 g_means = [] 37 b_means = [] 38 39 with its.device.ItsSession() as cam: 40 expt,_ = its.target.get_target_exposure_combos(cam)["midSensitivity"] 41 props = cam.get_camera_properties() 42 sens_range = props['android.sensor.info.sensitivityRange'] 43 sens_step = (sens_range[1] - sens_range[0]) / float(NUM_STEPS-1) 44 sensitivities = [sens_range[0] + i * sens_step for i in range(NUM_STEPS)] 45 46 for s in sensitivities: 47 req = its.objects.manual_capture_request(s, expt) 48 cap = cam.do_capture(req) 49 img = its.image.convert_capture_to_rgb_image(cap) 50 its.image.write_image( 51 img, "%s_iso=%04d.jpg" % (NAME, s)) 52 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1) 53 rgb_means = its.image.compute_image_means(tile) 54 r_means.append(rgb_means[0]) 55 g_means.append(rgb_means[1]) 56 b_means.append(rgb_means[2]) 57 58 # Draw a plot. 59 pylab.plot(sensitivities, r_means, 'r') 60 pylab.plot(sensitivities, g_means, 'g') 61 pylab.plot(sensitivities, b_means, 'b') 62 pylab.ylim([0,1]) 63 matplotlib.pyplot.savefig("%s_plot_means.png" % (NAME)) 64 65 # Test for pass/fail: check that each shot is brighter than the previous. 66 for means in [r_means, g_means, b_means]: 67 for i in range(len(means)-1): 68 assert(means[i+1] - means[i] > THRESHOLD_MIN_DIFF) 69 70 if __name__ == '__main__': 71 main() 72 73