'commit'
This commit is contained in:
@@ -137,43 +137,43 @@ def is_background_dimmed(image_path, threshold=80):
|
|||||||
return avg_brightness < threshold
|
return avg_brightness < threshold
|
||||||
|
|
||||||
|
|
||||||
from Util.EasyOcrKit import get_easyocr_reader
|
from Util.EasyOcrKit import get_easyocr_reader
|
||||||
|
|
||||||
# 预加载 EasyOCR Reader (单例模式)
|
# 预加载 EasyOCR Reader (单例模式)
|
||||||
def get_ocr_reader():
|
def get_ocr_reader():
|
||||||
return get_easyocr_reader(gpu=True)
|
return get_easyocr_reader(gpu=True)
|
||||||
|
|
||||||
|
|
||||||
def detect_price_info_container_cv(image_path):
|
def detect_price_info_container_cv(image_path):
|
||||||
"""
|
"""
|
||||||
使用 OCR 精准定位详情页中的价格入口文本(“全部时段”)。
|
使用 OCR 精准定位详情页中的价格入口文本(“全部时段”)。
|
||||||
返回: [x1, y1, x2, y2] 归一化坐标 (0-1000),如果未找到则返回 None
|
返回: [x1, y1, x2, y2] 归一化坐标 (0-1000),如果未找到则返回 None
|
||||||
"""
|
"""
|
||||||
img = read_image(image_path)
|
img = read_image(image_path)
|
||||||
if img is None:
|
if img is None:
|
||||||
return None
|
return None
|
||||||
h, w = img.shape[:2]
|
h, w = img.shape[:2]
|
||||||
|
|
||||||
keywords = ['全部时段']
|
keywords = ['全部时段']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
reader = get_ocr_reader()
|
reader = get_ocr_reader()
|
||||||
# 获取所有识别结果
|
# 获取所有识别结果
|
||||||
results = reader.read_text(img)
|
results = reader.read_text(img)
|
||||||
|
|
||||||
for (quad, text, prob) in results:
|
for (quad, text, prob) in results:
|
||||||
# 检查是否包含关键字
|
# 检查是否包含关键字
|
||||||
if any(kw in text for kw in keywords) and prob >= 0.5:
|
if any(kw in text for kw in keywords) and prob >= 0.5:
|
||||||
# 使用封装后的方法计算归一化矩形
|
# 使用封装后的方法计算归一化矩形
|
||||||
res = reader.get_normalized_rect(quad, w, h)
|
res = reader.get_normalized_rect(quad, w, h)
|
||||||
logger.info(f"[OCR识别] 找到文本: '{text}', 置信度: {prob:.4f}, 归一化坐标: {res}")
|
logger.info(f"[OCR识别] 找到文本: '{text}', 置信度: {prob:.4f}, 归一化坐标: {res}")
|
||||||
return res
|
return res
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"OCR 识别发生异常: {e}")
|
logger.error(f"OCR 识别发生异常: {e}")
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def detect_rabbit_ad_close(image_path, debug_dir=None):
|
def detect_rabbit_ad_close(image_path, debug_dir=None):
|
||||||
"""
|
"""
|
||||||
通过图形学算法检测“新电兔AI”广告的关闭按钮
|
通过图形学算法检测“新电兔AI”广告的关闭按钮
|
||||||
@@ -877,6 +877,18 @@ def crop_cards_from_image(img_path, output_dir=None, save_debug=True):
|
|||||||
# 准备 _vl.jpg (只画框,不画红点)
|
# 准备 _vl.jpg (只画框,不画红点)
|
||||||
vl_img = img.copy()
|
vl_img = img.copy()
|
||||||
|
|
||||||
|
# 预先在整张图上标记“兔子广告潜在区域”的蓝色矩形,方便标定
|
||||||
|
try:
|
||||||
|
rabbit_x1 = int(w * 0.04)
|
||||||
|
rabbit_x2 = int(w * 0.96)
|
||||||
|
rabbit_y1 = int(h * 0.74)
|
||||||
|
rabbit_y2 = int(h * 0.86)
|
||||||
|
cv2.rectangle(debug_img, (rabbit_x1, rabbit_y1), (rabbit_x2, rabbit_y2), (255, 0, 0), 3)
|
||||||
|
cv2.rectangle(vl_img, (rabbit_x1, rabbit_y1), (rabbit_x2, rabbit_y2), (255, 0, 0), 3)
|
||||||
|
logger.info(f" 标记兔子广告蓝色区域: X={rabbit_x1}-{rabbit_x2}, Y={rabbit_y1}-{rabbit_y2}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"标记兔子广告蓝色区域失败: {e}")
|
||||||
|
|
||||||
logger.info(f" Step [2.1/VL] 准备在 VL 图片上绘制 {len(final_cards)} 个场站的绿色方框...")
|
logger.info(f" Step [2.1/VL] 准备在 VL 图片上绘制 {len(final_cards)} 个场站的绿色方框...")
|
||||||
|
|
||||||
for idx, (y1, y2, x1, x2) in enumerate(final_cards):
|
for idx, (y1, y2, x1, x2) in enumerate(final_cards):
|
||||||
|
|||||||
Binary file not shown.
33
Tools/T9_DebugRabbitBlueRect.py
Normal file
33
Tools/T9_DebugRabbitBlueRect.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import os
|
||||||
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
|
|
||||||
|
IMAGE_PATH = r"d:\dsWork\aiData\Output\Screenshot_20260117_073155.jpg"
|
||||||
|
OUTPUT_PATH = r"d:\dsWork\aiData\Output\rabbit_blue_rect_20260117_073155.jpg"
|
||||||
|
|
||||||
|
|
||||||
|
def draw_rabbit_blue_rect(image_path: str, output_path: str):
|
||||||
|
if not os.path.exists(image_path):
|
||||||
|
raise FileNotFoundError(image_path)
|
||||||
|
|
||||||
|
img = Image.open(image_path).convert("RGB")
|
||||||
|
w, h = img.size
|
||||||
|
|
||||||
|
# 水平方向收一点边:左右各预留 4% 宽度
|
||||||
|
x1 = int(w * 0.04)
|
||||||
|
x2 = int(w * 0.96)
|
||||||
|
# 垂直方向:稍微向上抬一点上边界,下边界大幅向上
|
||||||
|
y1 = int(h * 0.74)
|
||||||
|
y2 = int(h * 0.86)
|
||||||
|
|
||||||
|
draw = ImageDraw.Draw(img)
|
||||||
|
draw.rectangle((x1, y1, x2, y2), outline="blue", width=4)
|
||||||
|
|
||||||
|
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
||||||
|
img.save(output_path)
|
||||||
|
print(f"saved: {output_path}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
draw_rabbit_blue_rect(IMAGE_PATH, OUTPUT_PATH)
|
||||||
|
|
||||||
Reference in New Issue
Block a user