test_predicted_burst.py revision cf8b3e81dc1437e119543334628b8fd124f9ca8a
1# Copyright 2013 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 pylab
19import os.path
20import matplotlib
21import matplotlib.pyplot
22import copy
23
24def main():
25    """Test that predicted AWB values come out on the right frames.
26    """
27    NAME = os.path.basename(__file__).split(".")[0]
28
29    def r2f(r):
30        return float(r["numerator"]) / float(r["denominator"])
31
32    reqs = its.objects.capture_request_list(
33        [its.objects.manual_capture_request(100,0.1)["captureRequest"]]*7 + \
34        [its.objects.manual_capture_request(300,33)["captureRequest"]]*7 + \
35        [its.objects.manual_capture_request(100,0.1)["captureRequest"]]*7
36        )
37
38    curve = sum([[i/63.0, pow(i/63.0, 1/2.2)] for i in range(64)], [])
39    for r in reqs["captureRequestList"]:
40        r["android.tonemap.mode"] = 0
41        r["android.tonemap.curveRed"] = curve
42        r["android.tonemap.curveGreen"] = curve
43        r["android.tonemap.curveBlue"] = curve
44
45    with its.device.ItsSession() as cam:
46        fnames, w, h, cap_mds = cam.do_capture(reqs)
47        for i, fname in enumerate(fnames):
48            img = its.image.load_yuv420_to_rgb_image(fname, w, h)
49            its.image.write_image(img, "%s_i=%02d.jpg" % (NAME, i))
50            cap_res = cap_mds[i]["captureResult"]
51            print "Predicted:", \
52                  cap_res["android.statistics.predictedColorGains"], \
53                  [r2f(t) for t in cap_res["android.statistics.predictedColorTransform"]]
54
55if __name__ == '__main__':
56    main()
57
58