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 its.target 20 import os.path 21 import numpy 22 23 def main(): 24 """Take long bursts of images and check that they're all identical. 25 26 Assumes a static scene. Can be used to idenfity if there are sporadic 27 frames that are processed differently or have artifacts. Uses manual 28 capture settings. 29 """ 30 NAME = os.path.basename(__file__).split(".")[0] 31 32 BURST_LEN = 50 33 BURSTS = 5 34 FRAMES = BURST_LEN * BURSTS 35 36 SPREAD_THRESH = 0.03 37 38 with its.device.ItsSession() as cam: 39 40 # Capture at the smallest resolution. 41 props = cam.get_camera_properties() 42 its.caps.skip_unless(its.caps.manual_sensor(props) and 43 its.caps.per_frame_control(props)) 44 45 _, fmt = its.objects.get_fastest_manual_capture_settings(props) 46 e, s = its.target.get_target_exposure_combos(cam)["minSensitivity"] 47 req = its.objects.manual_capture_request(s, e) 48 w,h = fmt["width"], fmt["height"] 49 50 # Capture bursts of YUV shots. 51 # Get the mean values of a center patch for each. 52 # Also build a 4D array, which is an array of all RGB images. 53 r_means = [] 54 g_means = [] 55 b_means = [] 56 imgs = numpy.empty([FRAMES,h,w,3]) 57 for j in range(BURSTS): 58 caps = cam.do_capture([req]*BURST_LEN, [fmt]) 59 for i,cap in enumerate(caps): 60 n = j*BURST_LEN + i 61 imgs[n] = its.image.convert_capture_to_rgb_image(cap) 62 tile = its.image.get_image_patch(imgs[n], 0.45, 0.45, 0.1, 0.1) 63 means = its.image.compute_image_means(tile) 64 r_means.append(means[0]) 65 g_means.append(means[1]) 66 b_means.append(means[2]) 67 68 # Dump all images. 69 print "Dumping images" 70 for i in range(FRAMES): 71 its.image.write_image(imgs[i], "%s_frame%03d.jpg"%(NAME,i)) 72 73 # The mean image. 74 img_mean = imgs.mean(0) 75 its.image.write_image(img_mean, "%s_mean.jpg"%(NAME)) 76 77 # Pass/fail based on center patch similarity. 78 for means in [r_means, g_means, b_means]: 79 spread = max(means) - min(means) 80 print spread 81 assert(spread < SPREAD_THRESH) 82 83 if __name__ == '__main__': 84 main() 85 86