test_param_exposure_time.py revision 87b68b020dd72c4cdcf3b8c1f9196c060f947991
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.device 17import its.objects 18import pylab 19import os.path 20import matplotlib 21import matplotlib.pyplot 22 23def main(): 24 """Test that the android.sensor.exposureTime parameter is applied. 25 """ 26 NAME = os.path.basename(__file__).split(".")[0] 27 28 # Pass/fail thresholds. 29 THRESHOLD_MAX_MIN_DIFF = 0.3 30 THRESHOLD_MAX_MIN_RATIO = 2.0 31 32 req = its.objects.capture_request( { 33 "android.control.mode": 0, 34 "android.control.aeMode": 0, 35 "android.control.awbMode": 0, 36 "android.control.afMode": 0, 37 "android.sensor.frameDuration": 0, 38 "android.sensor.sensitivity": 100 39 }) 40 41 exposures = range(1,101,20) # ms 42 r_means = [] 43 g_means = [] 44 b_means = [] 45 46 with its.device.ItsSession() as cam: 47 for e in exposures: 48 req["captureRequest"]["android.sensor.exposureTime"] = e*1000*1000 49 fname, w, h, cap_md = cam.do_capture(req) 50 img = its.image.load_yuv420_to_rgb_image(fname, w, h) 51 its.image.write_image( 52 img, "%s_time=%03dms.jpg" % (NAME, e)) 53 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1) 54 rgb_means = its.image.compute_image_means(tile) 55 r_means.append(rgb_means[0]) 56 g_means.append(rgb_means[1]) 57 b_means.append(rgb_means[2]) 58 59 # Draw a plot. 60 pylab.plot(exposures, r_means, 'r') 61 pylab.plot(exposures, g_means, 'g') 62 pylab.plot(exposures, b_means, 'b') 63 pylab.ylim([0,1]) 64 matplotlib.pyplot.savefig("%s_plot_means.png" % (NAME)) 65 66 # Test for pass/fail: just check that that images get brighter by an amount 67 # that is more than could be expected by random noise. Don't assume the 68 # curve has any specific shape or gradient. This test is just checking that 69 # the sensitivity parameter actually does something. Note the intensity 70 # may be clamped to 0 or 1 for part of the ramp, so only test that the 71 # brightness difference between the first and last samples are above a 72 # given threshold. 73 for means in [r_means, g_means, b_means]: 74 for i in range(len(means)-1): 75 assert(means[i] <= means[i+1]) 76 assert(means[-1] - means[0] > THRESHOLD_MAX_MIN_DIFF) 77 assert(means[-1] / means[0] > THRESHOLD_MAX_MIN_RATIO) 78 79if __name__ == '__main__': 80 main() 81 82