forked from Jarvis-K/wechat_jump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.py
executable file
·50 lines (39 loc) · 1.7 KB
/
play.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
from PyQt5 import QtCore
import play_dobot as dobot
import play_camera
import play_cv
def get_press_time(distance, rate=1.25):
# rate may change by different size of screen
return int(distance * rate)
class WechatJump(QtCore.QObject):
"""wechatJump Logic and Motion Part"""
runSig = QtCore.pyqtSignal()
runFlag = True
Eye = play_cv.Eye()
def runSigCall(self):
"""receive signal from AllForOne to stop jump"""
self.runFlag = False
def main(self, w_length, h_length, sig):
self.runFlag = True
self.runSig.connect(self.runSigCall)
# dobot_state = dobot.dType.ConnectDobot(dobot.api, "", 115200)[0]
# dobot.dType.SetPTPJointParams(api, 200, 200, 200, 200, 200, 200, 200, 200, isQueued=1)
# dobot.dType.SetHOMEParams(api, 251, -29, 150, 0, isQueued=1)
# main loop
for i in range(10000):
if not self.runFlag:
break
img_rgb, canny_img = play_camera.get_img(i)
if self.Eye.game_over(img_rgb):
break
img_rgb = self.Eye.find_player(img_rgb)
if img_rgb is None:
continue
img_rgb, dot_x, dot_y = self.Eye.find_dot(img_rgb, canny_img)
img_rgb, player_pos = self.Eye.tag_2_dots(img_rgb, dot_x, dot_y, i)
distance = ((player_pos[0] - dot_x) ** 2 + (player_pos[1] - dot_y) ** 2) ** 0.5
press_time = get_press_time(distance=distance)
print('distance = %.4f, press_time = %d' % (distance, press_time))
sig.emit(press_time)
dobot.play_1_loop(press_time)
# dobot.dType.DisconnectDobot(dobot.api)