Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 1 | # Copyright 2016 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 os |
| 16 | import re |
| 17 | import subprocess |
| 18 | import sys |
| 19 | import time |
| 20 | |
Clemenz Portmann | d440895 | 2018-10-12 08:51:49 -0700 | [diff] [blame] | 21 | import its.cv2image |
Clemenz Portmann | 9b752ed | 2018-03-21 12:35:15 -0700 | [diff] [blame] | 22 | import numpy as np |
| 23 | |
Clemenz Portmann | 7a3f7eb | 2019-08-01 13:08:50 -0700 | [diff] [blame] | 24 | LOAD_SCENE_DELAY = 2 # seconds |
| 25 | |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 26 | def main(): |
| 27 | """Load charts on device and display.""" |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 28 | scene = None |
leslieshaw | ad75890 | 2020-09-01 19:45:16 -0700 | [diff] [blame] | 29 | out_path = "" |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 30 | for s in sys.argv[1:]: |
| 31 | if s[:6] == 'scene=' and len(s) > 6: |
| 32 | scene = s[6:] |
| 33 | elif s[:7] == 'screen=' and len(s) > 7: |
| 34 | screen_id = s[7:] |
Clemenz Portmann | 8f07042 | 2017-11-27 16:06:33 -0800 | [diff] [blame] | 35 | elif s[:5] == 'dist=' and len(s) > 5: |
| 36 | chart_distance = float(re.sub('cm', '', s[5:])) |
| 37 | elif s[:4] == 'fov=' and len(s) > 4: |
| 38 | camera_fov = float(s[4:]) |
leslieshaw | ad75890 | 2020-09-01 19:45:16 -0700 | [diff] [blame] | 39 | elif s[:7] == "camera=" and len(s) > 7: |
leslieshaw | 2c00c68 | 2020-11-09 17:01:35 -0800 | [diff] [blame] | 40 | camera_id = str(s[7:]) |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 41 | |
| 42 | cmd = ('adb -s %s shell am force-stop com.google.android.apps.docs' % |
| 43 | screen_id) |
| 44 | subprocess.Popen(cmd.split()) |
| 45 | |
leslieshaw | ad75890 | 2020-09-01 19:45:16 -0700 | [diff] [blame] | 46 | if out_path != "": |
| 47 | scene_name = re.split("/|\.", out_path)[-2] |
| 48 | |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 49 | if not scene: |
| 50 | print 'Error: need to specify which scene to load' |
| 51 | assert False |
| 52 | |
Clemenz Portmann | a9afdd2 | 2016-09-21 07:52:57 -0700 | [diff] [blame] | 53 | if not screen_id: |
| 54 | print 'Error: need to specify screen serial' |
| 55 | assert False |
| 56 | |
Clemenz Portmann | d440895 | 2018-10-12 08:51:49 -0700 | [diff] [blame] | 57 | src_scene_path = os.path.join(os.environ['CAMERA_ITS_TOP'], 'tests', scene) |
| 58 | dst_scene_file = '/sdcard/Download/%s.pdf' % scene |
| 59 | chart_scaling = its.cv2image.calc_chart_scaling(chart_distance, camera_fov) |
| 60 | if np.isclose(chart_scaling, its.cv2image.SCALE_TELE_IN_WFOV_BOX, atol=0.01): |
Clemenz Portmann | 31ea19b | 2019-04-10 13:55:20 -0700 | [diff] [blame] | 61 | file_name = '%s_%sx_scaled.pdf' % ( |
Clemenz Portmann | d440895 | 2018-10-12 08:51:49 -0700 | [diff] [blame] | 62 | scene, str(its.cv2image.SCALE_TELE_IN_WFOV_BOX)) |
| 63 | elif np.isclose(chart_scaling, its.cv2image.SCALE_RFOV_IN_WFOV_BOX, atol=0.01): |
Clemenz Portmann | 31ea19b | 2019-04-10 13:55:20 -0700 | [diff] [blame] | 64 | file_name = '%s_%sx_scaled.pdf' % ( |
Clemenz Portmann | b1c43b0 | 2018-11-20 13:49:05 -0800 | [diff] [blame] | 65 | scene, str(its.cv2image.SCALE_RFOV_IN_WFOV_BOX)) |
Clemenz Portmann | 8f07042 | 2017-11-27 16:06:33 -0800 | [diff] [blame] | 66 | else: |
Clemenz Portmann | d440895 | 2018-10-12 08:51:49 -0700 | [diff] [blame] | 67 | file_name = '%s.pdf' % scene |
| 68 | src_scene_file = os.path.join(src_scene_path, file_name) |
| 69 | print 'Loading %s on %s' % (src_scene_file, screen_id) |
| 70 | cmd = 'adb -s %s push %s /mnt%s' % (screen_id, src_scene_file, |
| 71 | dst_scene_file) |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 72 | subprocess.Popen(cmd.split()) |
Clemenz Portmann | 7a3f7eb | 2019-08-01 13:08:50 -0700 | [diff] [blame] | 73 | time.sleep(LOAD_SCENE_DELAY) # wait-for-device doesn't always seem to work |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 74 | # The intent require PDF viewing app be installed on device. |
| 75 | # Also the first time such app is opened it might request some permission, |
| 76 | # so it's better to grant those permissions before using this script |
| 77 | cmd = ("adb -s %s wait-for-device shell am start -d 'file://%s'" |
Clemenz Portmann | d440895 | 2018-10-12 08:51:49 -0700 | [diff] [blame] | 78 | " -a android.intent.action.VIEW" % (screen_id, dst_scene_file)) |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 79 | subprocess.Popen(cmd.split()) |
leslieshaw | 354f92e | 2020-10-22 00:05:56 -0700 | [diff] [blame] | 80 | time.sleep(LOAD_SCENE_DELAY) |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 81 | |
leslieshaw | ad75890 | 2020-09-01 19:45:16 -0700 | [diff] [blame] | 82 | with its.device.ItsSession() as cam: |
| 83 | props = cam.get_camera_properties() |
Clemenz Portmann | ec9649f | 2021-01-20 08:17:42 -0800 | [diff] [blame] | 84 | props = cam.override_with_hidden_physical_camera_props(props) |
leslieshaw | ad75890 | 2020-09-01 19:45:16 -0700 | [diff] [blame] | 85 | cam.do_3a() |
| 86 | req = its.objects.fastest_auto_capture_request(props) |
| 87 | print "Capture an image to validate the light level" |
| 88 | cap = cam.do_capture(req) |
| 89 | img = its.image.convert_capture_to_rgb_image(cap) |
| 90 | its.image.write_image( |
| 91 | img, os.path.join(out_path, camera_id, scene, "validate_lighting.jpg")) |
| 92 | # Check if ITS is being run in WFoV or RFoV ITS rigs, and DUT's FoV. |
| 93 | if (np.isclose(chart_distance, its.cv2image.CHART_DISTANCE_RFOV, rtol=0.1) and |
| 94 | its.cv2image.FOV_THRESH_TELE <= camera_fov and |
| 95 | camera_fov <= its.cv2image.FOV_THRESH_WFOV): |
| 96 | its.image.validate_lighting(img) |
| 97 | elif (np.isclose(chart_distance, its.cv2image.CHART_DISTANCE_WFOV, rtol=0.1) and |
| 98 | camera_fov > its.cv2image.FOV_THRESH_WFOV): |
| 99 | its.image.validate_lighting(img) |
| 100 | |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 101 | if __name__ == '__main__': |
| 102 | main() |