• 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
39        # Converge 3A and get the estimates.
40        debug = its.caps.debug_mode()
41        if debug:
42            fmt = its.objects.get_largest_yuv_format(props)
43        else:
44            fmt = its.objects.get_smallest_yuv_format(props)
45        sens, exp, gains, xform, focus = cam.do_3a(get_results=True)
46        xform_rat = its.objects.float_to_rational(xform)
47        print "AE sensitivity %d, exposure %dms" % (sens, exp/1000000.0)
48        print "AWB gains", gains
49        print "AWB transform", xform
50        print "AF distance", focus
51
52        # Auto capture.
53        req = its.objects.auto_capture_request()
54        cap_auto = cam.do_capture(req, fmt)
55        img_auto = its.image.convert_capture_to_rgb_image(cap_auto)
56        its.image.write_image(img_auto, "%s_auto.jpg" % (NAME))
57        xform_a = its.objects.rational_to_float(
58                cap_auto["metadata"]["android.colorCorrection.transform"])
59        gains_a = cap_auto["metadata"]["android.colorCorrection.gains"]
60        print "Auto gains:", gains_a
61        print "Auto transform:", xform_a
62
63        # Manual capture 1: WB
64        req = its.objects.manual_capture_request(sens, exp, focus)
65        req["android.colorCorrection.transform"] = xform_rat
66        req["android.colorCorrection.gains"] = gains
67        cap_man1 = cam.do_capture(req, fmt)
68        img_man1 = its.image.convert_capture_to_rgb_image(cap_man1)
69        its.image.write_image(img_man1, "%s_manual_wb.jpg" % (NAME))
70        xform_m1 = its.objects.rational_to_float(
71                cap_man1["metadata"]["android.colorCorrection.transform"])
72        gains_m1 = cap_man1["metadata"]["android.colorCorrection.gains"]
73        print "Manual wb gains:", gains_m1
74        print "Manual wb transform:", xform_m1
75
76        # Manual capture 2: WB + tonemap
77        gamma = sum([[i/63.0,math.pow(i/63.0,1/2.2)] for i in xrange(64)],[])
78        req["android.tonemap.mode"] = 0
79        req["android.tonemap.curveRed"] = gamma
80        req["android.tonemap.curveGreen"] = gamma
81        req["android.tonemap.curveBlue"] = gamma
82        cap_man2 = cam.do_capture(req, fmt)
83        img_man2 = its.image.convert_capture_to_rgb_image(cap_man2)
84        its.image.write_image(img_man2, "%s_manual_wb_tm.jpg" % (NAME))
85        xform_m2 = its.objects.rational_to_float(
86                cap_man2["metadata"]["android.colorCorrection.transform"])
87        gains_m2 = cap_man2["metadata"]["android.colorCorrection.gains"]
88        print "Manual wb+tm gains:", gains_m2
89        print "Manual wb+tm transform:", xform_m2
90
91        # Check that the WB gains and transform reported in each capture
92        # result match with the original AWB estimate from do_3a.
93        for g,x in [(gains_a,xform_a),(gains_m1,xform_m1),(gains_m2,xform_m2)]:
94            assert(all([abs(xform[i] - x[i]) < 0.05 for i in range(9)]))
95            assert(all([abs(gains[i] - g[i]) < 0.05 for i in range(4)]))
96
97if __name__ == '__main__':
98    main()
99
100