From db89abc9498e041188c88dd1dcb83d116c433d8f Mon Sep 17 00:00:00 2001 From: deerandsea Date: Mon, 19 Feb 2024 15:23:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=20human=20demonstra?= =?UTF-8?q?tion=20=E4=B8=8B=E5=9B=BE=E7=89=87=E5=88=86=E5=88=AB=E7=8E=87?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=B1=8F=E5=B9=95=E5=B9=B6=E4=B8=94=E7=BD=AE?= =?UTF-8?q?=E4=BA=8E=E5=B1=8F=E5=B9=95=E9=A1=B6=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/step_recorder.py | 6 +++++- scripts/utils.py | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/step_recorder.py b/scripts/step_recorder.py index efb71a8..a3abfb5 100644 --- a/scripts/step_recorder.py +++ b/scripts/step_recorder.py @@ -9,7 +9,7 @@ from and_controller import list_all_devices, AndroidController, traverse_tree from config import load_config -from utils import print_with_color, draw_bbox_multi +from utils import print_with_color, draw_bbox_multi, get_screen_size arg_desc = "AppAgent - Human Demonstration" parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description=arg_desc) @@ -72,6 +72,7 @@ print_with_color("ERROR: Invalid device size!", "red") sys.exit() print_with_color(f"Screen resolution of {device}: {width}x{height}", "yellow") +_, screen_height = get_screen_size() print_with_color("Please state the goal of your following demo actions clearly, e.g. send a message to John", "blue") task_desc = input() @@ -109,6 +110,9 @@ elem_list.append(elem) labeled_img = draw_bbox_multi(screenshot_path, os.path.join(labeled_ss_dir, f"{demo_name}_{step}.png"), elem_list, True) + cv2.namedWindow('image', cv2.WINDOW_NORMAL) + cv2.setWindowProperty('image', cv2.WND_PROP_TOPMOST, 1) + cv2.resizeWindow('image', int(screen_height * width / height), screen_height) cv2.imshow("image", labeled_img) cv2.waitKey(0) cv2.destroyAllWindows() diff --git a/scripts/utils.py b/scripts/utils.py index ec19c45..cca75b3 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -3,6 +3,7 @@ import pyshine as ps from colorama import Fore, Style +from tkinter import Tk def print_with_color(text: str, color=""): @@ -98,3 +99,11 @@ def get_unit_len(n): def encode_image(image_path): with open(image_path, "rb") as image_file: return base64.b64encode(image_file.read()).decode('utf-8') + + +def get_screen_size(): + root = Tk() + width = root.winfo_screenwidth() + height = root.winfo_screenheight() + root.destroy() + return width, height