Home | History | Annotate | Download | only in scene1
      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 
     15 import its.image
     16 import its.caps
     17 import its.device
     18 import its.objects
     19 import os.path
     20 import pylab
     21 import matplotlib
     22 import matplotlib.pyplot
     23 import numpy
     24 
     25 def 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()
     32         its.caps.skip_unless(its.caps.ev_compensation(props))
     33 
     34         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)
     38         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 
     57         # 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)
     62         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 
     69 if __name__ == '__main__':
     70     main()
     71