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