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 settings latch on the right frame.
     27 
     28     Takes a bunch of shots using back-to-back requests, varying the capture
     29     request parameters between shots. Checks that the images that come back
     30     have the expected properties.
     31     """
     32     NAME = os.path.basename(__file__).split(".")[0]
     33 
     34     with its.device.ItsSession() as cam:
     35         props = cam.get_camera_properties()
     36         if not its.caps.full(props):
     37             print "Test skipped"
     38             return
     39 
     40         _,fmt = its.objects.get_fastest_manual_capture_settings(props)
     41         e, s = its.target.get_target_exposure_combos(cam)["midExposureTime"]
     42         e /= 2.0
     43 
     44         r_means = []
     45         g_means = []
     46         b_means = []
     47 
     48         reqs = [
     49             its.objects.manual_capture_request(s,  e,   True),
     50             its.objects.manual_capture_request(s,  e,   True),
     51             its.objects.manual_capture_request(s*2,e,   True),
     52             its.objects.manual_capture_request(s*2,e,   True),
     53             its.objects.manual_capture_request(s,  e,   True),
     54             its.objects.manual_capture_request(s,  e,   True),
     55             its.objects.manual_capture_request(s,  e*2, True),
     56             its.objects.manual_capture_request(s,  e,   True),
     57             its.objects.manual_capture_request(s*2,e,   True),
     58             its.objects.manual_capture_request(s,  e,   True),
     59             its.objects.manual_capture_request(s,  e*2, True),
     60             its.objects.manual_capture_request(s,  e,   True),
     61             its.objects.manual_capture_request(s,  e*2, True),
     62             its.objects.manual_capture_request(s,  e*2, True),
     63             ]
     64 
     65         caps = cam.do_capture(reqs, fmt)
     66         for i,cap in enumerate(caps):
     67             img = its.image.convert_capture_to_rgb_image(cap)
     68             its.image.write_image(img, "%s_i=%02d.jpg" % (NAME, i))
     69             tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
     70             rgb_means = its.image.compute_image_means(tile)
     71             r_means.append(rgb_means[0])
     72             g_means.append(rgb_means[1])
     73             b_means.append(rgb_means[2])
     74 
     75         # Draw a plot.
     76         idxs = range(len(r_means))
     77         pylab.plot(idxs, r_means, 'r')
     78         pylab.plot(idxs, g_means, 'g')
     79         pylab.plot(idxs, b_means, 'b')
     80         pylab.ylim([0,1])
     81         matplotlib.pyplot.savefig("%s_plot_means.png" % (NAME))
     82 
     83         g_avg = sum(g_means) / len(g_means)
     84         g_ratios = [g / g_avg for g in g_means]
     85         g_hilo = [g>1.0 for g in g_ratios]
     86         assert(g_hilo == [False, False, True, True, False, False, True,
     87                           False, True, False, True, False, True, True])
     88 
     89 if __name__ == '__main__':
     90     main()
     91 
     92