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