Yin-Chia Yeh | ab98ada | 2015-03-05 13:28:53 -0800 | [diff] [blame] | 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 | |
| 15 | import sys |
| 16 | import its.device |
| 17 | import its.objects |
| 18 | import its.image |
Yin-Chia Yeh | 9c0d926 | 2015-04-03 17:02:13 -0700 | [diff] [blame] | 19 | import its.caps |
Yin-Chia Yeh | 0e0276f | 2015-06-03 15:27:06 -0700 | [diff] [blame] | 20 | import re |
Yin-Chia Yeh | ab98ada | 2015-03-05 13:28:53 -0800 | [diff] [blame] | 21 | |
| 22 | def main(): |
| 23 | """capture a yuv image and save it to argv[1] |
| 24 | """ |
| 25 | camera_id = -1 |
| 26 | out_path = "" |
Yin-Chia Yeh | 0e0276f | 2015-06-03 15:27:06 -0700 | [diff] [blame] | 27 | scene_name = "" |
| 28 | scene_desc = "No requirement" |
Yin-Chia Yeh | 143612d | 2016-04-27 15:44:08 -0700 | [diff] [blame] | 29 | do_af = True |
Yin-Chia Yeh | ab98ada | 2015-03-05 13:28:53 -0800 | [diff] [blame] | 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:] |
Yin-Chia Yeh | 0e0276f | 2015-06-03 15:27:06 -0700 | [diff] [blame] | 35 | elif s[:6] == "scene=" and len(s) > 6: |
| 36 | scene_desc = s[6:] |
Yin-Chia Yeh | 143612d | 2016-04-27 15:44:08 -0700 | [diff] [blame] | 37 | elif s[:5] == "doAF=" and len(s) > 5: |
| 38 | do_af = s[5:] == "True" |
Yin-Chia Yeh | 0e0276f | 2015-06-03 15:27:06 -0700 | [diff] [blame] | 39 | |
| 40 | if out_path != "": |
| 41 | scene_name = re.split("/|\.", out_path)[-2] |
Yin-Chia Yeh | ab98ada | 2015-03-05 13:28:53 -0800 | [diff] [blame] | 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 + |
Yin-Chia Yeh | 0e0276f | 2015-06-03 15:27:06 -0700 | [diff] [blame] | 49 | " to frame the test scene: " + scene_name + |
| 50 | "\nThe scene setup should be: " + scene_desc ) |
Yin-Chia Yeh | ab98ada | 2015-03-05 13:28:53 -0800 | [diff] [blame] | 51 | # Converge 3A prior to capture. |
Yin-Chia Yeh | ab98ada | 2015-03-05 13:28:53 -0800 | [diff] [blame] | 52 | props = cam.get_camera_properties() |
huans | be34519 | 2018-01-26 17:15:24 -0800 | [diff] [blame^] | 53 | cam.do_3a(do_af=do_af, lock_ae=its.caps.ae_lock(props), |
| 54 | lock_awb=its.caps.awb_lock(props)) |
Yin-Chia Yeh | ab98ada | 2015-03-05 13:28:53 -0800 | [diff] [blame] | 55 | req = its.objects.fastest_auto_capture_request(props) |
Yin-Chia Yeh | 9c0d926 | 2015-04-03 17:02:13 -0700 | [diff] [blame] | 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 |
Yin-Chia Yeh | ab98ada | 2015-03-05 13:28:53 -0800 | [diff] [blame] | 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( |
Yin-Chia Yeh | 0e0276f | 2015-06-03 15:27:06 -0700 | [diff] [blame] | 68 | "Is the image okay for ITS " + scene_name +\ |
| 69 | "? (Y/N)").lower() |
Yin-Chia Yeh | ab98ada | 2015-03-05 13:28:53 -0800 | [diff] [blame] | 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 | |
| 76 | if __name__ == '__main__': |
| 77 | main() |