'commit'
This commit is contained in:
@@ -5,6 +5,7 @@ import time
|
||||
import shutil
|
||||
|
||||
import uiautomator2 as u2
|
||||
import cv2
|
||||
|
||||
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
@@ -87,6 +88,70 @@ async def run_single_image(image_path: str):
|
||||
await run_ocr_rect(image_path, log_path=LOG_FILE_PATH)
|
||||
|
||||
|
||||
async def run_output_regression():
|
||||
base_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Output")
|
||||
if not os.path.exists(base_dir):
|
||||
logger.error(f"离线回归目录不存在: {base_dir}")
|
||||
return
|
||||
files = sorted(os.listdir(base_dir))
|
||||
jpg_files = []
|
||||
for name in files:
|
||||
lower = name.lower()
|
||||
if not lower.endswith(".jpg"):
|
||||
continue
|
||||
if lower.endswith("_ocr_rect.jpg"):
|
||||
continue
|
||||
jpg_files.append(os.path.join(base_dir, name))
|
||||
if not jpg_files:
|
||||
logger.error("离线回归目录中不存在待检测的原始 JPG 截图。")
|
||||
return
|
||||
total = len(jpg_files)
|
||||
ok_count = 0
|
||||
for path in jpg_files:
|
||||
img = cv2.imread(path)
|
||||
if img is None:
|
||||
logger.error(f"无法读取图片: {path}")
|
||||
continue
|
||||
h, w = img.shape[:2]
|
||||
logger.info(f"开始离线校验: {path}")
|
||||
stations = await run_ocr_rect(path, log_path=LOG_FILE_PATH)
|
||||
if not stations:
|
||||
logger.error(f"离线校验失败: {path} 未识别到任何场站。")
|
||||
continue
|
||||
page_ok = True
|
||||
for st in stations:
|
||||
rect = st.get("rect") or []
|
||||
if not isinstance(rect, (list, tuple)) or len(rect) < 4:
|
||||
logger.error(f"场站缺少有效矩形信息: {st}")
|
||||
page_ok = False
|
||||
break
|
||||
x1, y1, x2, y2 = rect[0], rect[1], rect[2], rect[3]
|
||||
if not (0 <= x1 < x2 <= w and 0 <= y1 < y2 <= h):
|
||||
logger.error(f"矩形越界: {rect}, 图片尺寸=({w},{h})")
|
||||
page_ok = False
|
||||
break
|
||||
busy_list = st.get("busy_list") or []
|
||||
if not busy_list:
|
||||
logger.error(f"场站忙闲信息为空: {st}")
|
||||
page_ok = False
|
||||
break
|
||||
click_point = st.get("click_point") or st.get("click") or []
|
||||
if isinstance(click_point, (list, tuple)) and len(click_point) >= 2:
|
||||
cx, cy = click_point[0], click_point[1]
|
||||
if not (x1 <= cx <= x2 and y1 <= cy <= y2):
|
||||
logger.error(f"点击点不在矩形内部: click={click_point}, rect={rect}")
|
||||
page_ok = False
|
||||
break
|
||||
if page_ok:
|
||||
ok_count += 1
|
||||
logger.info(f"离线校验通过: {path}")
|
||||
else:
|
||||
logger.error(f"离线校验未通过: {path}")
|
||||
if ok_count != total:
|
||||
raise AssertionError(f"离线首屏 OCR+LLM 校验未全部通过: {ok_count}/{total}")
|
||||
logger.info(f"离线首屏 OCR+LLM 校验全部通过: {ok_count}/{total}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mode = "scroll"
|
||||
image_path = None
|
||||
@@ -99,6 +164,8 @@ if __name__ == "__main__":
|
||||
mode = "image"
|
||||
if len(sys.argv) >= 3:
|
||||
image_path = sys.argv[2]
|
||||
elif lower == "check":
|
||||
mode = "check"
|
||||
else:
|
||||
if any(lower.endswith(ext) for ext in [".jpg", ".jpeg", ".png"]):
|
||||
mode = "image"
|
||||
@@ -108,6 +175,8 @@ if __name__ == "__main__":
|
||||
asyncio.run(run_batch_local())
|
||||
elif mode == "image":
|
||||
asyncio.run(run_single_image(image_path))
|
||||
elif mode == "check":
|
||||
asyncio.run(run_output_regression())
|
||||
else:
|
||||
asyncio.run(run_scroll_capture())
|
||||
except KeyboardInterrupt:
|
||||
|
||||
Reference in New Issue
Block a user