'commit'
This commit is contained in:
74
Tools/T_DebugRabbitOffset.py
Normal file
74
Tools/T_DebugRabbitOffset.py
Normal 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()
|
||||
30
Tools/T_DebugRightAdOffset.py
Normal file
30
Tools/T_DebugRightAdOffset.py
Normal 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()
|
||||
Reference in New Issue
Block a user