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 numpy
     21 
     22 def main():
     23     """Test a sequence of shots with different tonemap curves.
     24     """
     25     NAME = os.path.basename(__file__).split(".")[0]
     26 
     27     # There should be 3 identical frames followed by a different set of
     28     # 3 identical frames.
     29     MAX_SAME_DELTA = 0.03  # match number in test_burst_sameness_manual
     30     MIN_DIFF_DELTA = 0.10
     31 
     32     with its.device.ItsSession() as cam:
     33         props = cam.get_camera_properties()
     34         its.caps.skip_unless(its.caps.manual_sensor(props) and
     35                              its.caps.manual_post_proc(props) and
     36                              its.caps.per_frame_control(props))
     37 
     38         debug = its.caps.debug_mode()
     39         largest_yuv = its.objects.get_largest_yuv_format(props)
     40         if debug:
     41             fmt = largest_yuv
     42         else:
     43             match_ar = (largest_yuv['width'], largest_yuv['height'])
     44             fmt = its.objects.get_smallest_yuv_format(props, match_ar=match_ar)
     45 
     46         sens, exp_time, _,_,f_dist = cam.do_3a(do_af=True,get_results=True)
     47 
     48         means = []
     49 
     50         # Capture 3 manual shots with a linear tonemap.
     51         req = its.objects.manual_capture_request(sens, exp_time, f_dist, True, props)
     52         for i in [0,1,2]:
     53             cap = cam.do_capture(req, fmt)
     54             img = its.image.convert_capture_to_rgb_image(cap)
     55             its.image.write_image(img, "%s_i=%d.jpg" % (NAME, i))
     56             tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
     57             means.append(tile.mean(0).mean(0))
     58 
     59         # Capture 3 manual shots with the default tonemap.
     60         req = its.objects.manual_capture_request(sens, exp_time, f_dist, False)
     61         for i in [3,4,5]:
     62             cap = cam.do_capture(req, fmt)
     63             img = its.image.convert_capture_to_rgb_image(cap)
     64             its.image.write_image(img, "%s_i=%d.jpg" % (NAME, i))
     65             tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
     66             means.append(tile.mean(0).mean(0))
     67 
     68         # Compute the delta between each consecutive frame pair.
     69         deltas = [numpy.max(numpy.fabs(means[i+1]-means[i])) \
     70                   for i in range(len(means)-1)]
     71         print "Deltas between consecutive frames:", deltas
     72 
     73         assert(all([abs(deltas[i]) < MAX_SAME_DELTA for i in [0,1,3,4]]))
     74         assert(abs(deltas[2]) > MIN_DIFF_DELTA)
     75 
     76 if __name__ == '__main__':
     77     main()
     78 
     79