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.015 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 sens, exp_time, _,_,f_dist = cam.do_3a(do_af=True,get_results=True) 39 40 means = [] 41 42 # Capture 3 manual shots with a linear tonemap. 43 req = its.objects.manual_capture_request(sens, exp_time, f_dist, True, props) 44 for i in [0,1,2]: 45 cap = cam.do_capture(req) 46 img = its.image.convert_capture_to_rgb_image(cap) 47 its.image.write_image(img, "%s_i=%d.jpg" % (NAME, i)) 48 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1) 49 means.append(tile.mean(0).mean(0)) 50 51 # Capture 3 manual shots with the default tonemap. 52 req = its.objects.manual_capture_request(sens, exp_time, f_dist, False) 53 for i in [3,4,5]: 54 cap = cam.do_capture(req) 55 img = its.image.convert_capture_to_rgb_image(cap) 56 its.image.write_image(img, "%s_i=%d.jpg" % (NAME, i)) 57 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1) 58 means.append(tile.mean(0).mean(0)) 59 60 # Compute the delta between each consecutive frame pair. 61 deltas = [numpy.max(numpy.fabs(means[i+1]-means[i])) \ 62 for i in range(len(means)-1)] 63 print "Deltas between consecutive frames:", deltas 64 65 assert(all([abs(deltas[i]) < MAX_SAME_DELTA for i in [0,1,3,4]])) 66 assert(abs(deltas[2]) > MIN_DIFF_DELTA) 67 68 if __name__ == '__main__': 69 main() 70 71