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 15 import its.image 16 import its.caps 17 import its.device 18 import its.objects 19 import its.target 20 import pylab 21 import os.path 22 import matplotlib 23 import matplotlib.pyplot 24 25 def main(): 26 """Test that settings latch on the right frame. 27 28 Takes a bunch of shots using back-to-back requests, varying the capture 29 request parameters between shots. Checks that the images that come back 30 have the expected properties. 31 """ 32 NAME = os.path.basename(__file__).split(".")[0] 33 34 with its.device.ItsSession() as cam: 35 props = cam.get_camera_properties() 36 its.caps.skip_unless(its.caps.full(props) and 37 its.caps.per_frame_control(props)) 38 39 _,fmt = its.objects.get_fastest_manual_capture_settings(props) 40 e, s = its.target.get_target_exposure_combos(cam)["midExposureTime"] 41 e /= 2.0 42 43 r_means = [] 44 g_means = [] 45 b_means = [] 46 47 reqs = [ 48 its.objects.manual_capture_request(s, e, True), 49 its.objects.manual_capture_request(s, e, True), 50 its.objects.manual_capture_request(s*2,e, True), 51 its.objects.manual_capture_request(s*2,e, True), 52 its.objects.manual_capture_request(s, e, True), 53 its.objects.manual_capture_request(s, e, True), 54 its.objects.manual_capture_request(s, e*2, True), 55 its.objects.manual_capture_request(s, e, True), 56 its.objects.manual_capture_request(s*2,e, True), 57 its.objects.manual_capture_request(s, e, True), 58 its.objects.manual_capture_request(s, e*2, True), 59 its.objects.manual_capture_request(s, e, True), 60 its.objects.manual_capture_request(s, e*2, True), 61 its.objects.manual_capture_request(s, e*2, True), 62 ] 63 64 caps = cam.do_capture(reqs, fmt) 65 for i,cap in enumerate(caps): 66 img = its.image.convert_capture_to_rgb_image(cap) 67 its.image.write_image(img, "%s_i=%02d.jpg" % (NAME, i)) 68 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1) 69 rgb_means = its.image.compute_image_means(tile) 70 r_means.append(rgb_means[0]) 71 g_means.append(rgb_means[1]) 72 b_means.append(rgb_means[2]) 73 74 # Draw a plot. 75 idxs = range(len(r_means)) 76 pylab.plot(idxs, r_means, 'r') 77 pylab.plot(idxs, g_means, 'g') 78 pylab.plot(idxs, b_means, 'b') 79 pylab.ylim([0,1]) 80 matplotlib.pyplot.savefig("%s_plot_means.png" % (NAME)) 81 82 g_avg = sum(g_means) / len(g_means) 83 g_ratios = [g / g_avg for g in g_means] 84 g_hilo = [g>1.0 for g in g_ratios] 85 assert(g_hilo == [False, False, True, True, False, False, True, 86 False, True, False, True, False, True, True]) 87 88 if __name__ == '__main__': 89 main() 90 91