• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15import its.image
16import its.device
17import its.objects
18import its.caps
19import os.path
20import numpy
21from matplotlib import pylab
22import matplotlib
23import matplotlib.pyplot
24
25def main():
26    """Test 3A lock + YUV burst (using auto settings).
27
28    This is a test that is designed to pass even on limited devices that
29    don't have MANUAL_SENSOR or PER_FRAME_CONTROLS. The test checks
30    YUV image consistency while the frame rate check is in CTS.
31    """
32    NAME = os.path.basename(__file__).split(".")[0]
33
34    BURST_LEN = 8
35    SPREAD_THRESH_MANUAL_SENSOR = 0.01
36    SPREAD_THRESH = 0.03
37    FPS_MAX_DIFF = 2.0
38
39    with its.device.ItsSession() as cam:
40        props = cam.get_camera_properties()
41        its.caps.skip_unless(its.caps.ae_lock(props) and
42                             its.caps.awb_lock(props))
43        mono_camera = its.caps.mono_camera(props)
44
45        # Converge 3A prior to capture.
46        cam.do_3a(do_af=True, lock_ae=True, lock_awb=True,
47                  mono_camera=mono_camera)
48
49        fmt = its.objects.get_largest_yuv_format(props)
50
51        # After 3A has converged, lock AE+AWB for the duration of the test.
52        req = its.objects.fastest_auto_capture_request(props)
53        req["android.control.awbLock"] = True
54        req["android.control.aeLock"] = True
55
56        # Capture bursts of YUV shots.
57        # Get the mean values of a center patch for each.
58        r_means = []
59        g_means = []
60        b_means = []
61        caps = cam.do_capture([req]*BURST_LEN, fmt)
62        for i,cap in enumerate(caps):
63            img = its.image.convert_capture_to_rgb_image(cap)
64            its.image.write_image(img, "%s_frame%d.jpg"%(NAME,i))
65            tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
66            means = its.image.compute_image_means(tile)
67            r_means.append(means[0])
68            g_means.append(means[1])
69            b_means.append(means[2])
70
71        # Pass/fail based on center patch similarity.
72        for means in [r_means, g_means, b_means]:
73            spread = max(means) - min(means)
74            print "Patch mean spread", spread, \
75                    " (min/max: ",  min(means), "/", max(means), ")"
76            threshold = SPREAD_THRESH_MANUAL_SENSOR \
77                    if its.caps.manual_sensor(props) else SPREAD_THRESH
78            assert(spread < threshold)
79
80if __name__ == '__main__':
81    main()
82
83