This commit is contained in:
HuangHai
2026-01-16 22:41:03 +08:00
parent b34b06e97b
commit 645e663345
6 changed files with 137 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
# 采集配置
SCROLL_DISTANCE_RATIO = 0.5
MAX_STATIONS_COUNT = 20
MAX_STATIONS_COUNT = 1
FIRST_RUN_ONLY_ONE_STATION = False
REDIS_STATION_EXPIRE = 120
DATA_RETENTION_DAYS = 365

View File

@@ -1,5 +1,5 @@
import numpy as np
from PIL import Image
from PIL import Image, ImageDraw
import os
import asyncio
import hashlib
@@ -156,10 +156,28 @@ class ReadImageKit:
norm_point = result["close_point"]
x = int(norm_point[0] / 1000 * primary_width)
y = int(norm_point[1] / 1000 * primary_height)
ad_type = result.get("ad_type", "unknown")
if ad_type == "rabbit":
offset_y = int(primary_height * 0.05)
offset_x = int(primary_width * 0.014)
y = min(primary_height - 1, y + offset_y)
x = min(primary_width - 1, x + offset_x)
try:
os.makedirs(TEMP_IMAGE_DIR, exist_ok=True)
img = Image.open(image_path).convert("RGB")
draw = ImageDraw.Draw(img)
r = max(6, int(primary_height * 0.012))
draw.ellipse((x - r, y - r, x + r, y + r), outline="red", width=4)
base = os.path.basename(image_path)
debug_path = os.path.join(TEMP_IMAGE_DIR, f"debug_click_{base}")
img.save(debug_path)
logger.info(f"保存广告关闭按钮点击预览图: {debug_path}")
except Exception as e:
logger.warning(f"保存广告关闭按钮点击预览图失败: {e}")
return {
"x": x,
"y": y,
"ad_type": result.get("ad_type", "unknown")
"ad_type": ad_type
}
except Exception as e:
@@ -171,6 +189,18 @@ class ReadImageKit:
norm_point = cv_rabbit_point
x = int(norm_point[0] * primary_width)
y = int(norm_point[1] * primary_height)
try:
os.makedirs(TEMP_IMAGE_DIR, exist_ok=True)
img = Image.open(image_path).convert("RGB")
draw = ImageDraw.Draw(img)
r = max(6, int(primary_height * 0.012))
draw.ellipse((x - r, y - r, x + r, y + r), outline="red", width=4)
base = os.path.basename(image_path)
debug_path = os.path.join(TEMP_IMAGE_DIR, f"debug_click_{base}")
img.save(debug_path)
logger.info(f"保存广告关闭按钮点击预览图(CV): {debug_path}")
except Exception as e:
logger.warning(f"保存广告关闭按钮点击预览图(CV)失败: {e}")
return {"x": x, "y": y, "ad_type": "rabbit"}
return None

View File

@@ -0,0 +1,74 @@
import os
from PIL import Image, ImageDraw
BASE_IMAGE = r"d:\dsWork\aiData\Output\debug_click_a0819f84-4174-4d71-ae52-71dc9631b93d.jpg"
OUTPUT_DIR = r"d:\dsWork\aiData\Output\debug_offset_candidates"
BEST_DY = -30
def find_red_circle_center(img):
w, h = img.size
pixels = img.load()
xs = []
ys = []
y_start = int(h * 0.5)
y_end = h
x_start = 0
x_end = int(w * 0.5)
for y in range(y_start, y_end):
for x in range(x_start, x_end):
r, g, b = pixels[x, y]
if r > 230 and g < 40 and b < 40:
xs.append(x)
ys.append(y)
if not xs:
raise RuntimeError("未在图像中找到红色圆圈像素")
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
return int(cx), int(cy)
def generate_vertical_candidates():
if not os.path.exists(BASE_IMAGE):
raise FileNotFoundError(BASE_IMAGE)
os.makedirs(OUTPUT_DIR, exist_ok=True)
img = Image.open(BASE_IMAGE).convert("RGB")
cx, cy = find_red_circle_center(img)
w, h = img.size
radius = max(6, int(h * 0.012))
offsets = [-40, -30, -20, -10, -5, 0, 5, 10, 15, 20]
for dy in offsets:
img2 = img.copy()
draw = ImageDraw.Draw(img2)
y2 = max(radius, min(h - radius - 1, cy + dy))
draw.ellipse((cx - radius, y2 - radius, cx + radius, y2 + radius), outline="lime", width=3)
name = f"candidate_dy_{dy}.jpg"
path = os.path.join(OUTPUT_DIR, name)
img2.save(path)
print(path)
def generate_horizontal_candidates():
if not os.path.exists(BASE_IMAGE):
raise FileNotFoundError(BASE_IMAGE)
os.makedirs(OUTPUT_DIR, exist_ok=True)
img = Image.open(BASE_IMAGE).convert("RGB")
cx, cy = find_red_circle_center(img)
w, h = img.size
radius = max(6, int(h * 0.012))
y2 = max(radius, min(h - radius - 1, cy + BEST_DY))
offsets = [-30, -20, -10, -5, 0, 5, 10, 20, 30]
for dx in offsets:
img2 = img.copy()
draw = ImageDraw.Draw(img2)
x2 = max(radius, min(w - radius - 1, cx + dx))
draw.ellipse((x2 - radius, y2 - radius, x2 + radius, y2 + radius), outline="cyan", width=3)
name = f"candidate_dx_{dx}.jpg"
path = os.path.join(OUTPUT_DIR, name)
img2.save(path)
print(path)
if __name__ == "__main__":
generate_vertical_candidates()
generate_horizontal_candidates()

View File

@@ -0,0 +1,30 @@
import os
from PIL import Image, ImageDraw
BASE_IMAGE = r"d:\dsWork\aiData\Output\Screenshot_20260116_223152.jpg"
OUTPUT_DIR = r"d:\dsWork\aiData\Output\debug_right_ad_candidates"
def generate_vertical_candidates():
if not os.path.exists(BASE_IMAGE):
raise FileNotFoundError(BASE_IMAGE)
os.makedirs(OUTPUT_DIR, exist_ok=True)
img = Image.open(BASE_IMAGE).convert("RGB")
w, h = img.size
base_x = int(w * 0.88)
ratios = [0.60, 0.64, 0.68, 0.70, 0.72, 0.74, 0.76, 0.78, 0.80, 0.83, 0.84]
radius = max(6, int(h * 0.012))
for r in ratios:
y = int(h * r)
y = max(radius, min(h - radius - 1, y))
img2 = img.copy()
draw = ImageDraw.Draw(img2)
draw.ellipse((base_x - radius, y - radius, base_x + radius, y + radius), outline="cyan", width=3)
name = f"right_candidate_y_{int(r*100)}.jpg"
path = os.path.join(OUTPUT_DIR, name)
img2.save(path)
print(path)
if __name__ == "__main__":
generate_vertical_candidates()