blob: d09f2fd753dcb6278ccc48ef466aa71a04d80f06 [file] [log] [blame]
Zhijun He6137f212014-11-20 13:47:11 -08001# 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
Zhijun He503da802015-02-04 14:35:38 -080016import its.caps
Zhijun He6137f212014-11-20 13:47:11 -080017import its.device
18import its.objects
19import os.path
20import pylab
21import matplotlib
22import matplotlib.pyplot
23import numpy
24
25def main():
26 """Tests that EV compensation is applied.
27 """
28 NAME = os.path.basename(__file__).split(".")[0]
29
30 with its.device.ItsSession() as cam:
31 props = cam.get_camera_properties()
Zhijun He503da802015-02-04 14:35:38 -080032 its.caps.skip_unless(its.caps.ev_compensation(props))
Zhijun He6137f212014-11-20 13:47:11 -080033
Yin-Chia Yeh518d53d2015-02-05 15:37:32 -080034 ev_per_step = its.objects.rational_to_float(
35 props['android.control.aeCompensationStep'])
36 steps_per_ev = int(1.0 / ev_per_step)
37 evs = range(-2 * steps_per_ev, 2 * steps_per_ev + 1, steps_per_ev)
Zhijun He6137f212014-11-20 13:47:11 -080038 lumas = []
39 for ev in evs:
40 # Re-converge 3A, and lock AE once converged. skip AF trigger as
41 # dark/bright scene could make AF convergence fail and this test
42 # doesn't care the image sharpness.
43 cam.do_3a(ev_comp=ev, lock_ae=True, do_af=False)
44
45 # Capture a single shot with the same EV comp and locked AE.
46 req = its.objects.auto_capture_request()
47 req['android.control.aeExposureCompensation'] = ev
48 req["android.control.aeLock"] = True
49 cap = cam.do_capture(req)
50 y = its.image.convert_capture_to_planes(cap)[0]
51 tile = its.image.get_image_patch(y, 0.45,0.45,0.1,0.1)
52 lumas.append(its.image.compute_image_means(tile)[0])
53
54 pylab.plot(evs, lumas, 'r')
55 matplotlib.pyplot.savefig("%s_plot_means.png" % (NAME))
56
Yin-Chia Yeh518d53d2015-02-05 15:37:32 -080057 # trim trailing 1.0s (for saturated image)
58 while lumas and lumas[-1] == 1.0:
59 lumas.pop(-1)
60 # Only allow positive EVs to give saturated image
61 assert(len(lumas) > 2)
Zhijun He6137f212014-11-20 13:47:11 -080062 luma_diffs = numpy.diff(lumas)
63 min_luma_diffs = min(luma_diffs)
64 print "Min of the luma value difference between adjacent ev comp: ", \
65 min_luma_diffs
66 # All luma brightness should be increasing with increasing ev comp.
67 assert(min_luma_diffs > 0)
68
69if __name__ == '__main__':
70 main()