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 15import its.image 16import its.device 17import its.objects 18import os.path 19import pprint 20import math 21import numpy 22import matplotlib.pyplot 23import mpl_toolkits.mplot3d 24 25def main(): 26 """Test that valid data comes back in CaptureResult objects. 27 """ 28 NAME = os.path.basename(__file__).split(".")[0] 29 30 def r2f(r): 31 return float(r["numerator"]) / float(r["denominator"]) 32 33 if not its.device.reboot_device_on_argv(): 34 its.device.reboot_device() 35 36 # Run a first pass, which starts with a 3A convergence step. 37 with its.device.ItsSession() as cam: 38 # Get 3A lock first, so the auto values in the capture result are 39 # populated properly. 40 r = [0,0,1,1] 41 sens,exp,awb_gains,awb_transform,_ = cam.do_3a(r,r,r,True,True,False) 42 43 # Capture an auto shot using the converged 3A. 44 req = its.objects.auto_capture_request() 45 fname, w, h, cap_res = cam.do_capture(req) 46 img = its.image.load_yuv420_to_rgb_image(fname, w, h) 47 its.image.write_image(img, "%s_n=1_pass=1_auto.jpg" % (NAME)) 48 auto_gains = cap_res["android.colorCorrection.gains"] 49 auto_transform = cap_res["android.colorCorrection.transform"] 50 51 # Capture a request using default (unit/identify) gains, and get the 52 # predicted gains and transform. 53 req = its.objects.manual_capture_request(sens, exp/(1000.0*1000.0)) 54 fname, w, h, cap_res = cam.do_capture(req) 55 img = its.image.load_yuv420_to_rgb_image(fname, w, h) 56 its.image.write_image(img, "%s_n=2_pass=1_identity.jpg" % (NAME)) 57 pred_gains_1 = cap_res["android.statistics.predictedColorGains"] 58 pred_transform_1 = cap_res["android.statistics.predictedColorTransform"] 59 60 # Capture a request using the predicted gains/transform. 61 req = its.objects.manual_capture_request(sens, exp/(1000.0*1000.0)) 62 req["android.colorCorrection.transform"] = pred_transform_1 63 req["android.colorCorrection.gains"] = pred_gains_1 64 fname, w, h, md_obj = cam.do_capture(req) 65 img = its.image.load_yuv420_to_rgb_image(fname, w, h) 66 its.image.write_image(img, "%s_n=3_pass=1_predicted.jpg" % (NAME)) 67 68 print "Pass 1 metering gains:", awb_gains 69 print "Pass 1 metering transform:", awb_transform 70 print "Pass 1 auto shot gains:", auto_gains 71 print "Pass 1 auto shot transform:", [r2f(t) for t in auto_transform] 72 print "Pass 1 predicted gains:", pred_gains_1 73 print "Pass 1 predicted transform:", [r2f(t) for t in pred_transform_1] 74 75 if not its.device.reboot_device_on_argv(): 76 its.device.reboot_device() 77 78 # Run a second pass after rebooting that doesn't start with 3A convergence. 79 with its.device.ItsSession() as cam: 80 # Capture a request using default (unit/identify) gains, and get the 81 # predicted gains and transform. 82 req = its.objects.manual_capture_request(sens, exp/(1000.0*1000.0)) 83 fname, w, h, cap_res = cam.do_capture(req) 84 img = its.image.load_yuv420_to_rgb_image(fname, w, h) 85 its.image.write_image(img, "%s_n=4_pass=2_identity.jpg" % (NAME)) 86 pred_gains_2 = cap_res["android.statistics.predictedColorGains"] 87 pred_transform_2 = cap_res["android.statistics.predictedColorTransform"] 88 89 # Capture a request using the predicted gains/transform. 90 req = its.objects.manual_capture_request(sens, exp/(1000.0*1000.0)) 91 req["android.colorCorrection.transform"] = pred_transform_2 92 req["android.colorCorrection.gains"] = pred_gains_2 93 fname, w, h, md_obj = cam.do_capture(req) 94 img = its.image.load_yuv420_to_rgb_image(fname, w, h) 95 its.image.write_image(img, "%s_n=5_pass=2_predicted.jpg" % (NAME)) 96 97 print "Pass 2 predicted gains:", pred_gains_2 98 print "Pass 2 predicted transform:", [r2f(t) for t in pred_transform_2] 99 100if __name__ == '__main__': 101 main() 102 103