-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_image_detection.py
More file actions
88 lines (77 loc) · 3.18 KB
/
test_image_detection.py
File metadata and controls
88 lines (77 loc) · 3.18 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
79
80
81
82
83
84
85
86
87
88
"""Test script to diagnose image detection issues."""
import pyautogui
import pygetwindow as gw
import time
from config.settings import Settings
def test_image_detection():
"""Test if we can find images on screen."""
# Activate window
print("Looking for Puzzles & Survival window...")
windows = gw.getWindowsWithTitle('Puzzles & Survival')
if windows:
window = windows[0]
print(f"Found window: {window.title}")
window.activate()
time.sleep(2)
else:
print("Window not found!")
return
# Test images to find
test_images = [
("Plus button", Settings.IMAGE_PLUS, Settings.PLUS_CONFIDENCE),
("Heal button", Settings.IMAGE_HEAL, Settings.HEAL_CONFIDENCE),
("Clear button", Settings.IMAGE_CLEAR, Settings.CLEAR_CONFIDENCE),
("Help button", Settings.IMAGE_HELP, 0.7),
]
print("\n" + "="*60)
print("Testing image detection with different confidence levels")
print("="*60)
for name, image_path, default_conf in test_images:
print(f"\n{name} ({image_path}):")
print(f" Default confidence: {default_conf}")
location = None
# Try with different confidence levels
for confidence in [0.9, 0.85, 0.8, 0.7, 0.6, 0.5]:
try:
location = pyautogui.locateOnScreen(
image_path,
confidence=confidence,
grayscale=True
)
if location:
print(f" [YES] Found at confidence {confidence}: {location}")
break
except pyautogui.ImageNotFoundException:
print(f" [NO] Not found at confidence {confidence}")
except Exception as e:
print(f" [ERROR] at confidence {confidence}: {str(e)[:80]}")
continue
# Try without grayscale
if not location:
print(f" Trying without grayscale...")
for confidence in [0.9, 0.85, 0.8, 0.7, 0.6, 0.5]:
try:
location = pyautogui.locateOnScreen(
image_path,
confidence=confidence,
grayscale=False
)
if location:
print(f" [YES] Found (no grayscale) at confidence {confidence}: {location}")
break
except pyautogui.ImageNotFoundException:
print(f" [NO] Not found (no grayscale) at confidence {confidence}")
except Exception as e:
print(f" [ERROR] (no grayscale) at confidence {confidence}: {str(e)[:80]}")
continue
print("\n" + "="*60)
print("Taking screenshot for manual inspection...")
screenshot = pyautogui.screenshot()
screenshot.save('test_detection_screen.png')
print("Screenshot saved to test_detection_screen.png")
# Get mouse position
print(f"\nCurrent mouse position: {pyautogui.position()}")
print("\nYou can manually move your mouse over the + button")
print("and check the coordinates to verify the detection area.")
if __name__ == '__main__':
test_image_detection()