This commit is contained in:
HuangHai
2026-01-15 09:06:27 +08:00
parent 9cc78ff125
commit f8af4dd9ae
13 changed files with 404 additions and 103 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, setup_logger, read_image
from Apps.TeLaiDian.Kit import draw_rectangles, setup_logger, read_image, detect_price_info_container_cv
from Apps.TeLaiDian.Config.Setting import SAFE_EXCLUDE_RATIO, BOTTOM_SAFE_EXCLUDE_RATIO, MIN_CARD_HEIGHT
# 初始化日志
@@ -60,44 +60,77 @@ class ReadImageKit:
async def find_price_entrance_vlm(self, image_path):
"""
使用 VLM 在详情页寻找价格入口(如:1.1556元/度 的卡片或价格信息按钮)
使用 VLM 在详情页寻找价格入口
重点识别:上方是大字价格(如 1.3435元/度),下方紧跟“全部时段 >”文字的区域
"""
prompt = """
分析这张特来电充电站详情页截图,找到进入“分时电价详情”的点击入口。
入口规则:
1. 只选择“价格信息”模块中“当前价”下方的红色电价数字(例如 1.0689 元/度、1.3435 元/度)。
2. 排除底部悬浮条或底部操作区中的红色价格(靠近“扫码充电”“立即充电”等按钮的区域)。
3. 排除“停车参考价”“停车费参考价”等与停车相关的区域。
4. 禁止选择页面顶部的标签栏,例如“价格 / 终端 / 电站 / 评论 / 周边”这一行中的任何文字或区域。
5. 如果页面没有“当前价”,才选择用于展示充电价格的按钮,如“价格信息”“电价详情”。
# 1. 尝试使用 CV 检测“价格信息”容器矩形
container_norm = detect_price_info_container_cv(image_path)
container_desc = ""
vlm_image_path = image_path
位置约束(尽量满足):
- Y 位置位于价格信息模块区域内:明显在顶部标签栏下方、在底部悬浮条上方。
- X 位置应位于左侧价格列区域(当前价所在列),避免会员价右侧列。
if container_norm:
# 如果找到了容器,绘制绿框诊断图
img = read_image(image_path)
if img is not None:
h, w = img.shape[:2]
x1 = int(container_norm[0] * w / 1000)
y1 = int(container_norm[1] * h / 1000)
x2 = int(container_norm[2] * w / 1000)
y2 = int(container_norm[3] * h / 1000)
# 在左侧划分出一个子区域(当前价区域)
# 价格信息容器通常左右平分,左侧是当前价,右侧是会员价
current_price_x2 = x1 + (x2 - x1) // 2
# 绘制绿框
# 我们把整个容器标绿,并特别说明左侧是目标
diag_path = image_path.replace(".jpg", "_price_box.jpg")
import cv2
diag_img = img.copy()
cv2.rectangle(diag_img, (x1, y1), (x2, y2), (0, 255, 0), 3)
cv2.line(diag_img, (current_price_x2, y1), (current_price_x2, y2), (0, 255, 0), 2)
from Apps.TeLaiDian.Kit import save_image
save_image(diag_path, diag_img)
logger.info(f"[CV] 已检测到价格容器并保存绿框诊断图: {diag_path}")
# 更新 VLM 使用的图片为带绿框的图片,或者在提示词中说明
vlm_image_path = diag_path
container_desc = f"\n**视觉辅助**:图中已用【绿色矩形框】标出了“价格信息”区域。该区域被中间竖线分为左右两块。请重点分析【左侧半块】(即“当前价”所在的灰色背景区域)。"
prompt = f"""
分析这张特来电充电站详情页截图,找到进入“电价详情”的点击入口。
{container_desc}
**核心识别目标**:
1. 在页面中上部区域(或绿框内的左侧部分)寻找价格显示模块。
2. 该模块包含**红色、加粗的大字价格数字**(例如:1.3435元/度)。
3. **绝对必要标识**:在价格数字的正下方,**必须能够清晰看到**文本“全部时段 >”或“全部时段”。
4. 点击目标是“全部时段 >”文字所在的中心位置。
**严格限制与排除**:
1. **严禁选择 y > 850 的区域**(即屏幕最底部的 15% 区域)。
2. **严禁选择底部的浮动条**:浮动条通常包含“扫码充电”按钮,严禁返回其坐标。
3. 如果绿框存在,请优先在绿框的【左侧区域】寻找。
请判断符合上述规则的价格入口是否存在,并给出其中心坐标。
输出格式为 JSON:
{
{{
"found": true/false,
"reason": "为什么认为这是入口(说明是否基于当前价红色价格,并确认未选顶部标签栏或底部悬浮条)",
"point": [x, y],
"type": "price_card" / "button"
}
"reason": "解释你看到了什么,是否在绿框内找到了‘全部时段 >’",
"point": [x, y] // 归一化坐标 [0-1000]
}}
"""
try:
res_text = await self.vlm.analyze_image(image_path, prompt)
res_text = await self.vlm.analyze_image(vlm_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
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')}")