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