• 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.caps
17import its.device
18import its.objects
19import os.path
20import math
21
22def main():
23    """Capture auto and manual shots that should look the same.
24
25    Manual shots taken with just manual WB, and also with manual WB+tonemap.
26
27    In all cases, the general color/look of the shots should be the same,
28    however there can be variations in brightness/contrast due to different
29    "auto" ISP blocks that may be disabled in the manual flows.
30    """
31    NAME = os.path.basename(__file__).split(".")[0]
32
33    with its.device.ItsSession() as cam:
34        props = cam.get_camera_properties()
35        its.caps.skip_unless(its.caps.manual_sensor(props) and
36                             its.caps.manual_post_proc(props) and
37                             its.caps.per_frame_control(props))
38        mono_camera = its.caps.mono_camera(props)
39
40        # Converge 3A and get the estimates.
41        debug = its.caps.debug_mode()
42        largest_yuv = its.objects.get_largest_yuv_format(props)
43        if debug:
44            fmt = largest_yuv
45        else:
46            match_ar = (largest_yuv['width'], largest_yuv['height'])
47            fmt = its.objects.get_smallest_yuv_format(props, match_ar=match_ar)
48        sens, exp, gains, xform, focus = cam.do_3a(get_results=True,
49                                                   mono_camera=mono_camera)
50        xform_rat = its.objects.float_to_rational(xform)
51        print "AE sensitivity %d, exposure %dms" % (sens, exp/1000000.0)
52        print "AWB gains", gains
53        print "AWB transform", xform
54        print "AF distance", focus
55
56        # Auto capture.
57        req = its.objects.auto_capture_request()
58        cap_auto = cam.do_capture(req, fmt)
59        img_auto = its.image.convert_capture_to_rgb_image(cap_auto)
60        its.image.write_image(img_auto, "%s_auto.jpg" % (NAME))
61        xform_a = its.objects.rational_to_float(
62                cap_auto["metadata"]["android.colorCorrection.transform"])
63        gains_a = cap_auto["metadata"]["android.colorCorrection.gains"]
64        print "Auto gains:", gains_a
65        print "Auto transform:", xform_a
66
67        # Manual capture 1: WB
68        req = its.objects.manual_capture_request(sens, exp, focus)
69        req["android.colorCorrection.transform"] = xform_rat
70        req["android.colorCorrection.gains"] = gains
71        cap_man1 = cam.do_capture(req, fmt)
72        img_man1 = its.image.convert_capture_to_rgb_image(cap_man1)
73        its.image.write_image(img_man1, "%s_manual_wb.jpg" % (NAME))
74        xform_m1 = its.objects.rational_to_float(
75                cap_man1["metadata"]["android.colorCorrection.transform"])
76        gains_m1 = cap_man1["metadata"]["android.colorCorrection.gains"]
77        print "Manual wb gains:", gains_m1
78        print "Manual wb transform:", xform_m1
79
80        # Manual capture 2: WB + tonemap
81        gamma = sum([[i/63.0,math.pow(i/63.0,1/2.2)] for i in xrange(64)],[])
82        req["android.tonemap.mode"] = 0
83        req["android.tonemap.curve"] = {
84            "red": gamma, "green": gamma, "blue": gamma}
85        cap_man2 = cam.do_capture(req, fmt)
86        img_man2 = its.image.convert_capture_to_rgb_image(cap_man2)
87        its.image.write_image(img_man2, "%s_manual_wb_tm.jpg" % (NAME))
88        xform_m2 = its.objects.rational_to_float(
89                cap_man2["metadata"]["android.colorCorrection.transform"])
90        gains_m2 = cap_man2["metadata"]["android.colorCorrection.gains"]
91        print "Manual wb+tm gains:", gains_m2
92        print "Manual wb+tm transform:", xform_m2
93
94        # Check that the WB gains and transform reported in each capture
95        # result match with the original AWB estimate from do_3a.
96        for g,x in [(gains_a,xform_a),(gains_m1,xform_m1),(gains_m2,xform_m2)]:
97            assert(all([abs(xform[i] - x[i]) < 0.05 for i in range(9)]))
98            assert(all([abs(gains[i] - g[i]) < 0.05 for i in range(4)]))
99
100if __name__ == '__main__':
101    main()
102
103