-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshawarma.py
181 lines (158 loc) · 6.29 KB
/
shawarma.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import time
import cv2
import numpy as np
import pyautogui
while True:
# 截屏并转换为灰度图像
screenshot = pyautogui.screenshot()
screenshot = cv2.cvtColor(np.array(screenshot), cv2.COLOR_RGB2BGR)
gray_screenshot = cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)
# --开始一天
# 加载目标图像
template = cv2.imread('kaishiyitian.png')
w, h = template.shape[1], template.shape[0]
# 使用模板匹配
result = cv2.matchTemplate(gray_screenshot, cv2.cvtColor(template, cv2.COLOR_BGR2GRAY), cv2.TM_CCOEFF_NORMED)
loc = np.where(result >= 0.95) # 设定阈值
for pt in zip(*loc[::-1]):
# 点击目标位置
pyautogui.mouseDown(pt[0] + w // 2, pt[1] + h // 2)
pyautogui.sleep(0.1) # 持续按下.1s
pyautogui.mouseUp()
break # 点击一次后退出
# check_empty
flag = 0
# 截屏并转换为灰度图像
screenshot = pyautogui.screenshot()
screenshot = cv2.cvtColor(np.array(screenshot), cv2.COLOR_RGB2BGR)
gray_screenshot = cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)
# potato mach
template = cv2.imread('empty_potato_mach.png')
# 使用模板匹配
result = cv2.matchTemplate(gray_screenshot, cv2.cvtColor(template, cv2.COLOR_BGR2GRAY), cv2.TM_CCOEFF_NORMED)
loc = np.where(result >= 0.9) # 设定阈值
if len(loc[0]) > 0:
flag = 1
print('empty potato mach!')
pyautogui.moveTo(2292,966)
pyautogui.mouseDown()
time.sleep(5)
pyautogui.mouseUp()
# potato
template = cv2.imread('empty_potato.png')
# 使用模板匹配
result = cv2.matchTemplate(gray_screenshot, cv2.cvtColor(template, cv2.COLOR_BGR2GRAY), cv2.TM_CCOEFF_NORMED)
loc = np.where(result >= 0.9) # 设定阈值
if len(loc[0]) > 0:
flag = 1
print('empty potato!')
pyautogui.moveTo(2060,906)
pyautogui.mouseDown()
pyautogui.mouseUp()
# meat
template = cv2.imread('empty_meat.png')
# 使用模板匹配
result = cv2.matchTemplate(gray_screenshot, cv2.cvtColor(template, cv2.COLOR_BGR2GRAY), cv2.TM_CCOEFF_NORMED)
loc = np.where(result >= 0.9) # 设定阈值
if len(loc[0]) > 0:
flag = 1
print('empty meat!')
pyautogui.mouseDown(513,1062)
for _ in range(5):
pyautogui.moveTo(633,900,duration=0.3)
pyautogui.moveTo(633, 500)
pyautogui.mouseUp()
# cucumber
template = cv2.imread('empty_cucumber.png')
# 使用模板匹配
result = cv2.matchTemplate(gray_screenshot, cv2.cvtColor(template, cv2.COLOR_BGR2GRAY), cv2.TM_CCOEFF_NORMED)
loc = np.where(result >= 0.9) # 设定阈值
if len(loc[0]) > 0:
flag = 1
time.sleep(0.3)
print('empty cucumber!')
pyautogui.moveTo(362, 800)
pyautogui.mouseDown()
pyautogui.mouseUp()
time.sleep(0.3)
for _ in range(10):
pyautogui.mouseDown(585,753)
pyautogui.mouseUp()
pyautogui.moveTo(362, 800)
pyautogui.mouseDown()
pyautogui.mouseUp()
# yogurt
template = cv2.imread('empty_yogurt.png')
# 使用模板匹配
result = cv2.matchTemplate(gray_screenshot, cv2.cvtColor(template, cv2.COLOR_BGR2GRAY), cv2.TM_CCOEFF_NORMED)
loc = np.where(result >= 0.9) # 设定阈值
if len(loc[0]) > 0:
flag = 1
print('empty yogurt!')
time.sleep(0.3)
pyautogui.moveTo(362, 800)
pyautogui.mouseDown()
pyautogui.mouseUp()
time.sleep(0.3)
for _ in range(10):
pyautogui.mouseDown(575, 872)
pyautogui.mouseUp()
pyautogui.moveTo(362, 800)
pyautogui.mouseDown()
pyautogui.mouseUp()
if flag == 0:
# shawarma start !!
# 截屏并转换为灰度图像
screenshot = pyautogui.screenshot()
screenshot = cv2.cvtColor(np.array(screenshot), cv2.COLOR_RGB2BGR)
gray_screenshot = cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)
# 点击卷饼
template = cv2.imread('empty_table.png')
w, h = template.shape[1], template.shape[0]
# 使用模板匹配
result = cv2.matchTemplate(gray_screenshot, cv2.cvtColor(template, cv2.COLOR_BGR2GRAY), cv2.TM_CCOEFF_NORMED)
loc = np.where(result >= 0.9) # 设定阈值
for pt in zip(*loc[::-1]):
# 点击目标位置
pyautogui.mouseDown(pt[0] + w // 6, pt[1] + h // 2)
pyautogui.mouseUp()
time.sleep(0.5)
pyautogui.moveTo(684,1007)
for _ in range(3):
pyautogui.mouseDown()
pyautogui.mouseUp()
pyautogui.moveTo(900, 1014)
for _ in range(3):
pyautogui.mouseDown()
pyautogui.mouseUp()
pyautogui.moveTo(1100, 1000)
for _ in range(3):
pyautogui.mouseDown()
pyautogui.mouseUp()
pyautogui.moveTo(1298, 1000)
for _ in range(3):
pyautogui.mouseDown()
pyautogui.mouseUp()
# check
screenshot = pyautogui.screenshot()
screenshot = cv2.cvtColor(np.array(screenshot), cv2.COLOR_RGB2BGR)
gray_screenshot = cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)
template = cv2.imread('full_shawarma.png')
# 使用模板匹配
result = cv2.matchTemplate(gray_screenshot, cv2.cvtColor(template, cv2.COLOR_BGR2GRAY),
cv2.TM_CCOEFF_NORMED)
loc = np.where(result >= 0.9) # 设定阈值
if len(loc[0]) == 0:
break
# juan
pyautogui.moveTo(1271,1251)
pyautogui.mouseDown()
pyautogui.moveTo(1281, 1095,duration=0.5)
pyautogui.mouseUp()
# baozhuang
time.sleep(0.3)
pyautogui.moveTo(1058,1178)
pyautogui.mouseDown()
pyautogui.moveTo(1500, 1182,duration=0.5)
pyautogui.mouseUp()
break # 点击一次后退出