| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- # -*- coding: utf-8 -*-
- """A/B 对比: 稳定版(VisionParser1) vs 交叉版(VisionParserCross) 同图实测
- 检查: 输出差异 / 耗时 / page_wrong一致性 / 调用次数(按日志行数)"""
- import sys
- import time
- from pathlib import Path
- ROOT = Path(__file__).parent
- sys.path.insert(0, str(ROOT))
- from ai_helper_vision1 import VisionParser1
- from ai_helper_vision_cross import VisionParserCross
- from PIL import Image
- IMAGES = [
- (r"screenshots\OV7T8PV8GEHYSCNB\step3\step3_b0.png", "甲巯咪唑片"),
- (r"screenshots\OV7T8PV8GEHYSCNB\step3\step3_b1.png", "甲巯咪唑片"),
- (r"screenshots\OV7T8PV8GEHYSCNB\step3\step3_b2.png", "甲巯咪唑片"),
- (r"screenshots\T4VK4LM7AAUOV8AY\step3\step3_b0.png", "甲巯咪唑片"),
- ]
- CROSS = VisionParserCross()
- STABLE = VisionParser1()
- def run(parser, img, kw, w, h):
- t0 = time.time()
- shops, status = parser.parse_shops(img, screen_size=(w, h), keyword=kw, crop_x=287)
- dt = time.time() - t0
- return shops, status, dt
- def sig(shops):
- return sorted((s[0], str(price_num := __import__("re").search(r"[\d.]+", s[2]).group(0)), s[1][:18])
- for s in shops)
- for rel, kw in IMAGES:
- img = str(ROOT / rel)
- w, h = Image.open(img).size
- print("=" * 78)
- print(f"{rel.split(chr(92))[-2]}_b{Path(img).stem[-1]} ({w}x{h})")
- s_shops, s_status, s_dt = run(STABLE, img, kw, w, h)
- print(f" [稳定] {s_status} {len(s_shops)}卡 {s_dt:.0f}s")
- for s in s_shops:
- print(f" {s[0][:14]} | {s[2]} | {s[1][:26]}")
- c_shops, c_status, c_dt = run(CROSS, img, kw, w, h)
- print(f" [交叉] {c_status} {len(c_shops)}卡 {c_dt:.0f}s")
- for s in c_shops:
- print(f" {s[0][:14]} | {s[2]} | {s[1][:26]}")
- same = (s_status == c_status) and (sig(s_shops) == sig(c_shops))
- print(f" → {'两版结果一致' if same else '★ 两版结果不同(上面对比)'} 耗时比 {c_dt/s_dt:.1f}x")
|