1# Copyright 2015 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 sys
16import its.device
17import its.objects
18import its.image
19import its.caps
20import re
21
22def main():
23    """capture a yuv image and save it to argv[1]
24    """
25    camera_id = -1
26    out_path = ""
27    scene_name = ""
28    scene_desc = "No requirement"
29    do_af = True
30    for s in sys.argv[1:]:
31        if s[:7] == "camera=" and len(s) > 7:
32            camera_id = s[7:]
33        elif s[:4] == "out=" and len(s) > 4:
34            out_path = s[4:]
35        elif s[:6] == "scene=" and len(s) > 6:
36            scene_desc = s[6:]
37        elif s[:5] == "doAF=" and len(s) > 5:
38            do_af = s[5:] == "True"
39
40    if out_path != "":
41        scene_name = re.split("/|\.", out_path)[-2]
42
43    if camera_id == -1:
44        print "Error: need to specify which camera to use"
45        assert(False)
46
47    with its.device.ItsSession() as cam:
48        raw_input("Press Enter after placing camera " + camera_id +
49                " to frame the test scene: " + scene_name +
50                "\nThe scene setup should be: " + scene_desc )
51        # Converge 3A prior to capture.
52        props = cam.get_camera_properties()
53        cam.do_3a(do_af=do_af, lock_ae=its.caps.ae_lock(props),
54                  lock_awb=its.caps.awb_lock(props))
55        req = its.objects.fastest_auto_capture_request(props)
56        if its.caps.ae_lock(props):
57            req["android.control.awbLock"] = True
58        if its.caps.awb_lock(props):
59            req["android.control.aeLock"] = True
60        while True:
61            print "Capture an image to check the test scene"
62            cap = cam.do_capture(req)
63            img = its.image.convert_capture_to_rgb_image(cap)
64            if out_path != "":
65                its.image.write_image(img, out_path)
66            print "Please check scene setup in", out_path
67            choice = raw_input(
68                "Is the image okay for ITS " + scene_name +\
69                "? (Y/N)").lower()
70            if choice == "y":
71                break
72            else:
73                raw_input("Press Enter after placing camera " + camera_id +
74                          " to frame the test scene")
75
76if __name__ == '__main__':
77    main()
78