-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnostaleScript2.py
69 lines (55 loc) · 2.27 KB
/
nostaleScript2.py
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
from PIL import Image, ImageGrab
import numpy as np
import cv2
import pygetwindow as gw
import pyautogui
import pygetwindow
up = Image.open('up.png')
down = Image.open('down.png')
left = Image.open('left.png')
right = Image.open('right.png')
up = np.array(up.convert('L'))
down = np.array(down.convert('L'))
left = np.array(left.convert('L'))
right = np.array(right.convert('L'))
window = pygetwindow.getWindowsWithTitle("Nostale")[0]
def upFoo():
result = cv2.matchTemplate(screenshot, up, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
# Check if the reference image is found in the screenshot
if max_val >= 0.8: # You can adjust the threshold value for matching accuracy
print("up")
pyautogui.press("up")
def downFoo():
result = cv2.matchTemplate(screenshot, down, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
# Check if the reference image is found in the screenshot
if max_val >= 0.8: # You can adjust the threshold value for matching accuracy
print("down")
pyautogui.press("down")
def leftFoo():
result = cv2.matchTemplate(screenshot, left, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
# Check if the reference image is found in the screenshot
if max_val >= 0.8: # You can adjust the threshold value for matching accuracy
print("left")
pyautogui.press("left")
def rightFoo():
result = cv2.matchTemplate(screenshot, right, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
# Check if the reference image is found in the screenshot
if max_val >= 0.8: # You can adjust the threshold value for matching accuracy
print("right")
pyautogui.press("right")
while True:
x = window.left + 297 # x-coordinate of the top-left corner of the ROI
y = window.top + 220 # y-coordinate of the top-left corner of the ROI
width = 991 - 297 # width of the ROI
height = 810 - 220 # height of the ROI
screenshot = pyautogui.screenshot(region=(x, y, width, height))
screenshot = np.array(screenshot)
screenshot = cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)
upFoo()
downFoo()
rightFoo()
leftFoo()