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 os.path 19import pylab 20import matplotlib 21import matplotlib.pyplot 22import numpy 23 24def main(): 25 """Tests that EV compensation is applied. 26 """ 27 NAME = os.path.basename(__file__).split(".")[0] 28 29 MAX_LUMA_DELTA_THRESH = 0.01 30 AVG_LUMA_DELTA_THRESH = 0.001 31 32 with its.device.ItsSession() as cam: 33 props = cam.get_camera_properties() 34 cam.do_3a() 35 36 # Capture auto shots, but with a linear tonemap. 37 req = its.objects.auto_capture_request() 38 req["android.tonemap.mode"] = 0 39 req["android.tonemap.curveRed"] = (0.0, 0.0, 1.0, 1.0) 40 req["android.tonemap.curveGreen"] = (0.0, 0.0, 1.0, 1.0) 41 req["android.tonemap.curveBlue"] = (0.0, 0.0, 1.0, 1.0) 42 43 evs = range(-4,5) 44 lumas = [] 45 for ev in evs: 46 req['android.control.aeExposureCompensation'] = ev 47 cap = cam.do_capture(req) 48 y = its.image.convert_capture_to_planes(cap)[0] 49 tile = its.image.get_image_patch(y, 0.45,0.45,0.1,0.1) 50 lumas.append(its.image.compute_image_means(tile)[0]) 51 52 ev_step_size_in_stops = its.objects.rational_to_float( 53 props['android.control.aeCompensationStep']) 54 luma_increase_per_step = pow(2, ev_step_size_in_stops) 55 expected_lumas = [lumas[0] * pow(luma_increase_per_step, i) \ 56 for i in range(len(evs))] 57 58 pylab.plot(evs, lumas, 'r') 59 pylab.plot(evs, expected_lumas, 'b') 60 matplotlib.pyplot.savefig("%s_plot_means.png" % (NAME)) 61 62 luma_diffs = [expected_lumas[i] - lumas[i] for i in range(len(evs))] 63 max_diff = max(luma_diffs) 64 avg_diff = sum(luma_diffs) / len(luma_diffs) 65 print "Max delta between modeled and measured lumas:", max_diff 66 print "Avg delta between modeled and measured lumas:", avg_diff 67 assert(max_diff < MAX_LUMA_DELTA_THRESH) 68 assert(avg_diff < AVG_LUMA_DELTA_THRESH) 69 70if __name__ == '__main__': 71 main() 72