1d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# Copyright 2013 The Android Open Source Project 2d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# 3d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# Licensed under the Apache License, Version 2.0 (the "License"); 4d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# you may not use this file except in compliance with the License. 5d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# You may obtain a copy of the License at 6d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# 7d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# http://www.apache.org/licenses/LICENSE-2.0 8d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# 9d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# Unless required by applicable law or agreed to in writing, software 10d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# distributed under the License is distributed on an "AS IS" BASIS, 11d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# See the License for the specific language governing permissions and 13d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight# limitations under the License. 14d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 15d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knightimport its.image 16d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knightimport its.device 17d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knightimport its.objects 18d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knightimport os.path 19d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knightimport pprint 20d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knightimport math 21d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knightimport numpy 22d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knightimport matplotlib.pyplot 23d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knightimport mpl_toolkits.mplot3d 24d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 25d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knightdef main(): 26d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight """Test that valid data comes back in CaptureResult objects. 27d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight """ 28d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight NAME = os.path.basename(__file__).split(".")[0] 29d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 30d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight def r2f(r): 31d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight return float(r["numerator"]) / float(r["denominator"]) 32d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 33d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight if not its.device.reboot_device_on_argv(): 34d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight its.device.reboot_device() 35d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 36d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight # Run a first pass, which starts with a 3A convergence step. 37d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight with its.device.ItsSession() as cam: 38d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight # Get 3A lock first, so the auto values in the capture result are 39d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight # populated properly. 40d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight r = [0,0,1,1] 41d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight sens,exp,awb_gains,awb_transform,_ = cam.do_3a(r,r,r,True,True,False) 42d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 43d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight # Capture an auto shot using the converged 3A. 44d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight req = its.objects.auto_capture_request() 454902d71d230d21639be817a83e8998230a6ff5e0Timothy Knight fname, w, h, cap_res = cam.do_capture(req) 46d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight img = its.image.load_yuv420_to_rgb_image(fname, w, h) 47d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight its.image.write_image(img, "%s_n=1_pass=1_auto.jpg" % (NAME)) 48d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight auto_gains = cap_res["android.colorCorrection.gains"] 49d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight auto_transform = cap_res["android.colorCorrection.transform"] 50d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 51d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight # Capture a request using default (unit/identify) gains, and get the 52d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight # predicted gains and transform. 53d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight req = its.objects.manual_capture_request(sens, exp/(1000.0*1000.0)) 544902d71d230d21639be817a83e8998230a6ff5e0Timothy Knight fname, w, h, cap_res = cam.do_capture(req) 55d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight img = its.image.load_yuv420_to_rgb_image(fname, w, h) 56d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight its.image.write_image(img, "%s_n=2_pass=1_identity.jpg" % (NAME)) 57d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight pred_gains_1 = cap_res["android.statistics.predictedColorGains"] 58d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight pred_transform_1 = cap_res["android.statistics.predictedColorTransform"] 59d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 60d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight # Capture a request using the predicted gains/transform. 61d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight req = its.objects.manual_capture_request(sens, exp/(1000.0*1000.0)) 624902d71d230d21639be817a83e8998230a6ff5e0Timothy Knight req["android.colorCorrection.transform"] = pred_transform_1 634902d71d230d21639be817a83e8998230a6ff5e0Timothy Knight req["android.colorCorrection.gains"] = pred_gains_1 64d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight fname, w, h, md_obj = cam.do_capture(req) 65d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight img = its.image.load_yuv420_to_rgb_image(fname, w, h) 66d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight its.image.write_image(img, "%s_n=3_pass=1_predicted.jpg" % (NAME)) 67d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 68d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight print "Pass 1 metering gains:", awb_gains 69d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight print "Pass 1 metering transform:", awb_transform 70d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight print "Pass 1 auto shot gains:", auto_gains 71d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight print "Pass 1 auto shot transform:", [r2f(t) for t in auto_transform] 72d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight print "Pass 1 predicted gains:", pred_gains_1 73d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight print "Pass 1 predicted transform:", [r2f(t) for t in pred_transform_1] 74d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 75d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight if not its.device.reboot_device_on_argv(): 76d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight its.device.reboot_device() 77d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 78d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight # Run a second pass after rebooting that doesn't start with 3A convergence. 79d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight with its.device.ItsSession() as cam: 80d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight # Capture a request using default (unit/identify) gains, and get the 81d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight # predicted gains and transform. 82d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight req = its.objects.manual_capture_request(sens, exp/(1000.0*1000.0)) 834902d71d230d21639be817a83e8998230a6ff5e0Timothy Knight fname, w, h, cap_res = cam.do_capture(req) 84d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight img = its.image.load_yuv420_to_rgb_image(fname, w, h) 85d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight its.image.write_image(img, "%s_n=4_pass=2_identity.jpg" % (NAME)) 86d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight pred_gains_2 = cap_res["android.statistics.predictedColorGains"] 87d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight pred_transform_2 = cap_res["android.statistics.predictedColorTransform"] 88d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 89d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight # Capture a request using the predicted gains/transform. 90d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight req = its.objects.manual_capture_request(sens, exp/(1000.0*1000.0)) 914902d71d230d21639be817a83e8998230a6ff5e0Timothy Knight req["android.colorCorrection.transform"] = pred_transform_2 924902d71d230d21639be817a83e8998230a6ff5e0Timothy Knight req["android.colorCorrection.gains"] = pred_gains_2 93d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight fname, w, h, md_obj = cam.do_capture(req) 94d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight img = its.image.load_yuv420_to_rgb_image(fname, w, h) 95d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight its.image.write_image(img, "%s_n=5_pass=2_predicted.jpg" % (NAME)) 96d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 97d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight print "Pass 2 predicted gains:", pred_gains_2 98d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight print "Pass 2 predicted transform:", [r2f(t) for t in pred_transform_2] 99d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 100d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knightif __name__ == '__main__': 101d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight main() 102d7dfa1e033245cb60aec98210b6e1d428e4227d6Timothy Knight 103