This commit is contained in:
HuangHai
2026-01-18 09:44:03 +08:00
parent d883b668c6
commit bea73da605
75 changed files with 139 additions and 74 deletions

View File

@@ -14,7 +14,7 @@ if project_root not in sys.path:
from Apps.XinDianTu.Kit import setup_logger, take_screenshot
from Apps.XinDianTu.Config.Setting import SCROLL_DISTANCE_RATIO, WAIT_AFTER_SCROLL
from Apps.XinDianTu.FirstPageKit import run_ocr_rect
from Apps.XinDianTu.FirstPageKit import run_ocr_rect, run_batch_in_dir
LOGS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Logs")
@@ -39,7 +39,7 @@ async def capture_list_page(d, base_dir: str, index: int):
logger.exception(f"[{index}] 运行 OCR 绿框测试失败: {e}")
async def run():
async def run_scroll_capture():
logger.info("请先手动打开微信并进入新电途小程序的场站列表第一页。")
d = u2.connect()
@@ -60,17 +60,56 @@ async def run():
shutil.rmtree(path)
os.makedirs(base_dir, exist_ok=True)
for i in range(1, 11):
for i in range(1, 6):
await capture_list_page(d, base_dir, i)
if i < 10:
if i < 5:
logger.info(f"[{i}] 向上滑动,scale={SCROLL_DISTANCE_RATIO},等待 {WAIT_AFTER_SCROLL} 秒后继续截图。")
d.swipe_ext("up", scale=SCROLL_DISTANCE_RATIO)
await asyncio.sleep(WAIT_AFTER_SCROLL)
async def run_batch_local():
base_dir = os.path.dirname(os.path.abspath(__file__))
logger.info(f"批量处理目录中的 JPG 文件: {base_dir}")
await run_batch_in_dir(base_dir, log_path=LOG_FILE_PATH)
async def run_single_image(image_path: str):
if not image_path:
logger.error("单图模式下需要提供图片路径。")
return
if not os.path.isabs(image_path):
image_path = os.path.abspath(image_path)
if not os.path.exists(image_path):
logger.error(f"指定的图片不存在: {image_path}")
return
logger.info(f"单图 OCR 测试,图片路径: {image_path}")
await run_ocr_rect(image_path, log_path=LOG_FILE_PATH)
if __name__ == "__main__":
mode = "scroll"
image_path = None
if len(sys.argv) >= 2:
arg1 = sys.argv[1]
lower = arg1.lower()
if lower == "batch":
mode = "batch"
elif lower == "image":
mode = "image"
if len(sys.argv) >= 3:
image_path = sys.argv[2]
else:
if any(lower.endswith(ext) for ext in [".jpg", ".jpeg", ".png"]):
mode = "image"
image_path = arg1
try:
asyncio.run(run())
if mode == "batch":
asyncio.run(run_batch_local())
elif mode == "image":
asyncio.run(run_single_image(image_path))
else:
asyncio.run(run_scroll_capture())
except KeyboardInterrupt:
logger.info("用户手动中断测试脚本。")
except Exception as e: