blob: c1bd79ef6799e6f47f192cb274e79847b4d334f4 [file] [log] [blame]
# Copyright 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import re
import subprocess
import sys
import time
import its.cv2image
import numpy as np
LOAD_SCENE_DELAY = 2 # seconds
def main():
"""Load charts on device and display."""
scene = None
out_path = ""
for s in sys.argv[1:]:
if s[:6] == 'scene=' and len(s) > 6:
scene = s[6:]
elif s[:7] == 'screen=' and len(s) > 7:
screen_id = s[7:]
elif s[:5] == 'dist=' and len(s) > 5:
chart_distance = float(re.sub('cm', '', s[5:]))
elif s[:4] == 'fov=' and len(s) > 4:
camera_fov = float(s[4:])
elif s[:7] == "camera=" and len(s) > 7:
camera_id = str(s[7:])
cmd = ('adb -s %s shell am force-stop com.google.android.apps.docs' %
screen_id)
subprocess.Popen(cmd.split())
if out_path != "":
scene_name = re.split("/|\.", out_path)[-2]
if not scene:
print 'Error: need to specify which scene to load'
assert False
if not screen_id:
print 'Error: need to specify screen serial'
assert False
src_scene_path = os.path.join(os.environ['CAMERA_ITS_TOP'], 'tests', scene)
dst_scene_file = '/sdcard/Download/%s.pdf' % scene
chart_scaling = its.cv2image.calc_chart_scaling(chart_distance, camera_fov)
if np.isclose(chart_scaling, its.cv2image.SCALE_TELE_IN_WFOV_BOX, atol=0.01):
file_name = '%s_%sx_scaled.pdf' % (
scene, str(its.cv2image.SCALE_TELE_IN_WFOV_BOX))
elif np.isclose(chart_scaling, its.cv2image.SCALE_RFOV_IN_WFOV_BOX, atol=0.01):
file_name = '%s_%sx_scaled.pdf' % (
scene, str(its.cv2image.SCALE_RFOV_IN_WFOV_BOX))
else:
file_name = '%s.pdf' % scene
src_scene_file = os.path.join(src_scene_path, file_name)
print 'Loading %s on %s' % (src_scene_file, screen_id)
cmd = 'adb -s %s push %s /mnt%s' % (screen_id, src_scene_file,
dst_scene_file)
subprocess.Popen(cmd.split())
time.sleep(LOAD_SCENE_DELAY) # wait-for-device doesn't always seem to work
# The intent require PDF viewing app be installed on device.
# Also the first time such app is opened it might request some permission,
# so it's better to grant those permissions before using this script
cmd = ("adb -s %s wait-for-device shell am start -d 'file://%s'"
" -a android.intent.action.VIEW" % (screen_id, dst_scene_file))
subprocess.Popen(cmd.split())
time.sleep(LOAD_SCENE_DELAY)
with its.device.ItsSession() as cam:
props = cam.get_camera_properties()
props = cam.override_with_hidden_physical_camera_props(props)
cam.do_3a()
req = its.objects.fastest_auto_capture_request(props)
print "Capture an image to validate the light level"
cap = cam.do_capture(req)
img = its.image.convert_capture_to_rgb_image(cap)
its.image.write_image(
img, os.path.join(out_path, camera_id, scene, "validate_lighting.jpg"))
# Check if ITS is being run in WFoV or RFoV ITS rigs, and DUT's FoV.
if (np.isclose(chart_distance, its.cv2image.CHART_DISTANCE_RFOV, rtol=0.1) and
its.cv2image.FOV_THRESH_TELE <= camera_fov and
camera_fov <= its.cv2image.FOV_THRESH_WFOV):
its.image.validate_lighting(img)
elif (np.isclose(chart_distance, its.cv2image.CHART_DISTANCE_WFOV, rtol=0.1) and
camera_fov > its.cv2image.FOV_THRESH_WFOV):
its.image.validate_lighting(img)
if __name__ == '__main__':
main()