Home | History | Annotate | Download | only in scene1
      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.device
     17 import its.objects
     18 import os.path
     19 import numpy
     20 import pylab
     21 import matplotlib
     22 import matplotlib.pyplot
     23 
     24 def main():
     25     """Test 3A lock + YUV burst (using auto settings).
     26 
     27     This is a test that is designed to pass even on limited devices that
     28     don't have MANUAL_SENSOR or PER_FRAME_CONTROLS. (They must be able to
     29     capture bursts with full res @ full frame rate to pass, however).
     30     """
     31     NAME = os.path.basename(__file__).split(".")[0]
     32 
     33     BURST_LEN = 8
     34     SPREAD_THRESH = 0.005
     35     FPS_MAX_DIFF = 2.0
     36 
     37     with its.device.ItsSession() as cam:
     38         props = cam.get_camera_properties()
     39 
     40         # Converge 3A prior to capture.
     41         cam.do_3a(do_af=True, lock_ae=True, lock_awb=True)
     42 
     43         # After 3A has converged, lock AE+AWB for the duration of the test.
     44         req = its.objects.fastest_auto_capture_request(props)
     45         req["android.control.awbLock"] = True
     46         req["android.control.aeLock"] = True
     47 
     48         # Capture bursts of YUV shots.
     49         # Get the mean values of a center patch for each.
     50         r_means = []
     51         g_means = []
     52         b_means = []
     53         caps = cam.do_capture([req]*BURST_LEN)
     54         for i,cap in enumerate(caps):
     55             img = its.image.convert_capture_to_rgb_image(cap)
     56             its.image.write_image(img, "%s_frame%d.jpg"%(NAME,i))
     57             tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
     58             means = its.image.compute_image_means(tile)
     59             r_means.append(means[0])
     60             g_means.append(means[1])
     61             b_means.append(means[2])
     62 
     63         # Pass/fail based on center patch similarity.
     64         for means in [r_means, g_means, b_means]:
     65             spread = max(means) - min(means)
     66             print "Patch mean spread", spread, \
     67                    " (min/max: ",  min(means), "/", max(means), ")"
     68             assert(spread < SPREAD_THRESH)
     69 
     70         # Also ensure that the burst was at full frame rate.
     71         fmt_code = 0x23
     72         configs = props['android.scaler.streamConfigurationMap']\
     73                        ['availableStreamConfigurations']
     74         min_duration = None
     75         for cfg in configs:
     76             if cfg['format'] == fmt_code and cfg['input'] == False and \
     77                     cfg['width'] == caps[0]["width"] and \
     78                     cfg['height'] == caps[0]["height"]:
     79                 min_duration = cfg["minFrameDuration"]
     80         assert(min_duration is not None)
     81         tstamps = [c['metadata']['android.sensor.timestamp'] for c in caps]
     82         deltas = [tstamps[i]-tstamps[i-1] for i in range(1,len(tstamps))]
     83         actual_fps = 1.0 / (max(deltas) / 1000000000.0)
     84         actual_fps_max = 1.0 / (min(deltas) / 1000000000.0)
     85         max_fps = 1.0 / (min_duration / 1000000000.0)
     86         print "Measure FPS min/max", actual_fps, "/", actual_fps_max
     87         print "FPS measured %.1f, max advertized %.1f" %(actual_fps, max_fps)
     88         assert(max_fps - FPS_MAX_DIFF <= actual_fps <= max_fps + FPS_MAX_DIFF)
     89 
     90 if __name__ == '__main__':
     91     main()
     92 
     93