-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadjust_grid_size.py
More file actions
78 lines (69 loc) · 3.07 KB
/
Copy pathadjust_grid_size.py
File metadata and controls
78 lines (69 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
調整網格尺寸工具
用於調整網格的寬度和高度,保持左上角位置不變
"""
from find_grid_position import draw_grid_on_image
from image_recognition import recognize_grid, visualize_grid
def test_grid_size(img_path="game_screenshot.png",
grid_x=438, grid_y=138,
grid_width=742, grid_height=721,
adjust_width=0, adjust_height=0):
"""
測試調整後的網格尺寸
adjust_width: 寬度調整量(正數增加,負數減少)
adjust_height: 高度調整量(正數增加,負數減少)
"""
new_width = grid_width + adjust_width
new_height = grid_height + adjust_height
print(f"測試尺寸:")
print(f" grid_x = {grid_x}")
print(f" grid_y = {grid_y}")
print(f" grid_width = {new_width} (原始 {grid_width} + 調整 {adjust_width})")
print(f" grid_height = {new_height} (原始 {grid_height} + 調整 {adjust_height})")
# 生成標記圖片
output_path = f"grid_size_w{adjust_width}_h{adjust_height}.png"
draw_grid_on_image(img_path, grid_x, grid_y, new_width, new_height, output_path)
print(f"\n已生成標記圖片:{output_path}")
# 測試識別
print("\n正在測試識別...")
grid = recognize_grid(img_path, grid_x, grid_y, new_width, new_height, debug=False)
print("\n識別結果:")
visualize_grid(grid)
return new_width, new_height
if __name__ == "__main__":
import sys
print("="*60)
print("網格尺寸調整工具")
print("="*60)
print("\n當前參數:")
print(" 左上角:x=438, y=138")
print(" 尺寸:寬度=742, 高度=721")
print("\n如果框沒有正確框住格子,請調整:")
print(" - 寬度:增加或減少多少像素?")
print(" - 高度:增加或減少多少像素?")
print("\n或者直接測試調整:")
print(" python adjust_grid_size.py <adjust_width> <adjust_height>")
print(" 例如:python adjust_grid_size.py -20 -30 (寬度減少20,高度減少30)")
if len(sys.argv) >= 3:
try:
adjust_width = int(sys.argv[1])
adjust_height = int(sys.argv[2])
test_grid_size(adjust_width=adjust_width, adjust_height=adjust_height)
except ValueError:
print("錯誤:請提供有效的數字")
else:
# 測試幾個常見的調整值
print("\n正在測試幾個常見的尺寸調整...")
print("(通常需要減少高度,讓框更緊貼格子)")
test_cases = [
(0, -50, "高度減少50"),
(0, -30, "高度減少30"),
(0, -20, "高度減少20"),
(0, -10, "高度減少10"),
(-20, -30, "寬度減少20,高度減少30"),
(-10, -20, "寬度減少10,高度減少20"),
(0, 10, "高度增加10"),
]
for adjust_width, adjust_height, desc in test_cases:
print(f"\n--- 測試:{desc} (w={adjust_width}, h={adjust_height}) ---")
test_grid_size(adjust_width=adjust_width, adjust_height=adjust_height)