This commit is contained in:
HuangHai
2026-01-15 07:29:51 +08:00
parent a3fd56c5cd
commit 3e9fc3737e
10 changed files with 532 additions and 457 deletions

View File

@@ -10,7 +10,7 @@ if project_root not in sys.path:
sys.path.append(project_root)
from Util.VLMKit import VLMKit
from Apps.TeLaiDian.Kit import draw_rectangles, detect_cards_cv, setup_logger, read_image, detect_wide_rounded_card_cv
from Apps.TeLaiDian.Kit import draw_rectangles, setup_logger, read_image
from Apps.TeLaiDian.Config.Setting import SAFE_EXCLUDE_RATIO, BOTTOM_SAFE_EXCLUDE_RATIO, MIN_CARD_HEIGHT
# 初始化日志
@@ -20,41 +20,71 @@ class ReadImageKit:
def __init__(self):
self.vlm = VLMKit()
async def find_price_tab_vlm(self, image_path):
"""
使用 VLM 在详情页顶部标签栏中寻找“价格”标签的点击位置
"""
prompt = """
分析这张特来电充电站详情页截图,找到顶部标签栏中“价格”两个字所在的点击区域中心。
要求:
1. 仅在页面最上方的标签栏里查找,该标签栏通常包含“价格 / 终端 / 电站 / 评论 / 周边”等文字。
2. 不要选择下面“价格信息”模块中的数字(例如 1.0689 元/度)或其它文本。
3. 不要选择最顶端系统状态栏或返回按钮等区域。
输出格式为 JSON:
{
"found": true/false,
"reason": "为什么认为这个位置是顶部“价格”标签",
"point": [x, y] // 归一化坐标,范围 [0-1000]
}
"""
try:
res_text = await self.vlm.analyze_image(image_path, prompt)
json_str = self.vlm.extract_json(res_text)
data = json.loads(json_str)
if data.get("found") and data.get("point"):
p = data["point"]
img = read_image(image_path)
if img is not None:
h, w = img.shape[:2]
actual_p = [int(p[0] * w / 1000), int(p[1] * h / 1000)]
bbox = [actual_p[0]-60, actual_p[1]-30, actual_p[0]+60, actual_p[1]+30]
draw_rectangles(image_path, bboxes=[bbox], click_points=[actual_p])
logger.info(f"已生成价格标签诊断图片: {image_path.replace('.jpg', '_tab_vl.jpg')}")
return data
except Exception as e:
logger.error(f"VLM 寻找价格标签失败: {e}")
return {"found": False}
async def find_price_entrance_vlm(self, image_path):
"""
使用 VLM 在详情页寻找价格入口(如:1.1556元/度 的卡片或价格信息按钮)
"""
prompt = """
分析这张特来电充电站详情页截图,找到进入“分时电价详情”的点击入口。
入口优先级和特征如下:
1. 首选:页面中有文字“当前价”,其正下方一行通常是红色的电价数字,
例如 “1.1317 元/度”、“1.1556 元/度”等,请优先选择这行红色价格数字所在区域。
2. 如果页面同时存在“停车参考价”“停车费参考价”等字样,请不要选择这些区域,
只选择与充电“当前价”直接对应的红色价格数字。
3. 如果页面没有“当前价”字样,则可以退而求其次,选择明显用于展示
充电价格的卡片或按钮,例如写有“价格信息”“电价详情”的区域。
入口规则:
1. 只选择“价格信息”模块中“当前价”下方的红色电价数字(例如 1.0689 元/度、1.3435 元/度)。
2. 排除底部悬浮条或底部操作区中的红色价格(靠近“扫码充电”“立即充电”等按钮的区域)。
3. 排除“停车参考价”“停车费参考价”等与停车相关的区域。
4. 禁止选择页面顶部的标签栏,例如“价格 / 终端 / 电站 / 评论 / 周边”这一行中的任何文字或区域。
5. 如果页面没有“当前价”,才选择用于展示充电价格的按钮,如“价格信息”“电价详情”。
位置约束(尽量满足):
- Y 位置位于价格信息模块区域内:明显在顶部标签栏下方、在底部悬浮条上方。
- X 位置应位于左侧价格列区域(当前价所在列),避免会员价右侧列。
请判断符合上述规则的价格入口是否存在,并给出其中心坐标。
输出格式为 JSON:
{
"found": true/false,
"reason": "为什么认为这是入口(说明是否基于当前价红色价格)",
"point": [x, y], // 归一化坐标 [0-1000],例如 [500, 600] 代表屏幕中心偏下
"reason": "为什么认为这是入口(说明是否基于当前价红色价格,并确认未选顶部标签栏或底部悬浮条)",
"point": [x, y],
"type": "price_card" / "button"
}
"""
try:
cv_bboxes = detect_wide_rounded_card_cv(image_path, min_width_ratio=0.8, min_y_ratio=0.5)
if cv_bboxes:
img = read_image(image_path)
if img is not None:
h, w = img.shape[:2]
bx1, by1, bx2, by2 = cv_bboxes[0]
cx = (bx1 + bx2) // 2
cy = (by1 + by2) // 2
draw_rectangles(image_path, bboxes=[cv_bboxes[0]], click_points=[[cx, cy]])
return {"found": True, "reason": "cv", "point": [int(cx * 1000 / w), int(cy * 1000 / h)], "type": "price_card"}
res_text = await self.vlm.analyze_image(image_path, prompt)
json_str = self.vlm.extract_json(res_text)
data = json.loads(json_str)
@@ -68,7 +98,7 @@ class ReadImageKit:
h, w = img.shape[:2]
actual_p = [int(p[0] * w / 1000), int(p[1] * h / 1000)]
# 生成虚拟 bbox
bbox = [actual_p[0]-50, actual_p[1]-30, actual_p[0]+50, actual_p[1]+30]
bbox = [actual_p[0]-60, actual_p[1]-40, actual_p[0]+60, actual_p[1]+40]
draw_rectangles(image_path, bboxes=[bbox], click_points=[actual_p])
logger.info(f"已生成价格入口诊断图片: {image_path.replace('.jpg', '_vl.jpg')}")
@@ -119,6 +149,44 @@ class ReadImageKit:
logger.error(f"VLM 寻找关闭按钮失败: {e}")
return {"has_ad": False}
async def check_warm_popup_vlm(self, image_path):
"""
检测详情页是否存在“温馨提示/下次再说”弹窗
"""
prompt = """
分析这张特来电充电站详情页截图,判断是否存在带有“下次再说”或“下次现说”文案的温馨提示弹窗。
要求:
1. 只关注覆盖在详情页上方的弹窗或遮罩,其上包含“下次再说”“下次现说”等文字按钮。
2. 不要将正常页面中的列表项、价格卡片、终端状态等区域误判为弹窗。
3. 如果存在该弹窗,请给出“下次再说”按钮的大致点击中心位置。
输出格式为 JSON:
{
"has_popup": true/false,
"reason": "为什么认为有或没有温馨提示弹窗",
"button_point": [x, y] // 归一化坐标,范围 [0-1000],没有则为 null
}
"""
try:
res_text = await self.vlm.analyze_image(image_path, prompt)
json_str = self.vlm.extract_json(res_text)
data = json.loads(json_str)
if data.get("has_popup") and data.get("button_point"):
p = data["button_point"]
img = read_image(image_path)
if img is not None:
h, w = img.shape[:2]
actual_p = [int(p[0] * w / 1000), int(p[1] * h / 1000)]
bbox = [actual_p[0]-80, actual_p[1]-40, actual_p[0]+80, actual_p[1]+40]
draw_rectangles(image_path, bboxes=[bbox], click_points=[actual_p])
logger.info(f"已生成温馨提示弹窗诊断图片: {image_path.replace('.jpg', '_warm_vl.jpg')}")
return data
except Exception as e:
logger.error(f"VLM 检测温馨提示弹窗失败: {e}")
return {"has_popup": False}
async def check_wrong_page_vlm(self, image_path):
"""
检查是否误触进入了错误的页面(如:新人福利、我的卡券、活动页等)