sos-bot/debug_screenshot.py
bachko 3309a47e10 Initial commit: SoS bot framework
- ADB client (connect, tap, swipe, screencap, app control)
- Vision module (in-memory screenshot + OpenCV template matching)
- Action loader (auto-discovers .py files in actions/)
- Engine (screenshot → detect → act loop with YAML playbook)
- 12 built-in actions: tap, click, wait, swipe, find,
  find_and_click, wait_until, click_seq, keyevent, app, log
- Example custom action template
- Debug screenshot tool for template creation
- Detailed plan.md with 20 actions across 9 phases
- Sample playbook with 10 steps
2026-07-09 13:52:31 +00:00

78 lines
2.4 KiB
Python

"""
Debug screenshot tool — capture a clean screenshot from the emulator
and save it so you can crop reference templates from it.
Usage:
source .venv/bin/activate
python debug_screenshot.py # saves sos_screenshot_<timestamp>.png
python debug_screenshot.py --output my_screen.png
python debug_screenshot.py --port 5556
"""
import argparse
import logging
import os
import sys
from datetime import datetime
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from core.adb import AdbClient
from core.vision import Vision
def main():
parser = argparse.ArgumentParser(
description="Capture a debug screenshot from the emulator"
)
parser.add_argument("--host", default="127.0.0.1")
parser.add_argument("--port", type=int, default=5555)
parser.add_argument("--output", "-o", help="Output PNG path")
parser.add_argument("-v", "--verbose", action="store_true")
args = parser.parse_args()
level = logging.DEBUG if args.verbose else logging.INFO
logging.basicConfig(level=level, format="%(message)s")
log = logging.getLogger("sos")
if not args.output:
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
args.output = f"sos_screenshot_{ts}.png"
print(f"[*] Connecting ADB to {args.host}:{args.port}...")
adb = AdbClient(args.host, args.port)
adb.connect()
if not adb.is_connected():
print("[!] ADB not connected. Is BlueStacks running with ADB enabled?")
sys.exit(1)
print(f"[*] ADB connected: {adb.serial}")
vision = Vision(adb)
print("[*] Capturing screenshot (in-memory)...")
vision.capture()
w, h = vision.size
print(f"[*] Device resolution: {w}x{h}")
print(f"[*] Saving to {args.output}...")
vision.save_debug_screenshot(args.output)
# Also print pixel info utility
print(f"\n[*] Saved: {args.output} ({os.path.getsize(args.output)} bytes)")
print()
print("NEXT STEPS:")
print(f" 1. Open {args.output} in an image editor")
print(f" 2. Crop the button/icon you want to click")
print(f" 3. Save the crop to templates/<name>.png")
print(f" 4. Add a step in playbook/default.yaml referencing it")
print()
print("PIXEL CHECK: read a pixel color from the saved image:")
print(f" python -c \"from PIL import Image; im=Image.open('{args.output}'); print(im.getpixel((100,200)))\"")
print()
adb.disconnect()
if __name__ == "__main__":
main()