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        cam.do_3a(do_af=do_af, lock_ae=True, lock_awb=True)
53        props = cam.get_camera_properties()
54        req = its.objects.fastest_auto_capture_request(props)
55        if its.caps.ae_lock(props):
56            req["android.control.awbLock"] = True
57        if its.caps.awb_lock(props):
58            req["android.control.aeLock"] = True
59        while True:
60            print "Capture an image to check the test scene"
61            cap = cam.do_capture(req)
62            img = its.image.convert_capture_to_rgb_image(cap)
63            if out_path != "":
64                its.image.write_image(img, out_path)
65            print "Please check scene setup in", out_path
66            choice = raw_input(
67                "Is the image okay for ITS " + scene_name +\
68                "? (Y/N)").lower()
69            if choice == "y":
70                break
71            else:
72                raw_input("Press Enter after placing camera " + camera_id +
73                          " to frame the test scene")
74
75if __name__ == '__main__':
76    main()
77