|
@@ -5,12 +5,11 @@ from time import sleep, time
|
|
|
import pyautogui as gui
|
|
|
import sched
|
|
|
import cv2
|
|
|
-from collections import namedtuple
|
|
|
|
|
|
|
|
|
cv2.namedWindow('View', cv2.WINDOW_NORMAL)
|
|
|
DEFAULT_MONITOR = 3
|
|
|
-DEBUG = True
|
|
|
+DEBUG = False
|
|
|
scheduler = sched.scheduler(time, sleep)
|
|
|
dilation_kernel = np.array([[0,0,0], [1, 1, 1], [0,0,0]]).astype('uint8')
|
|
|
|
|
@@ -123,47 +122,54 @@ if __name__ == '__main__':
|
|
|
dino_pos = np.where(labeledScreen==dino_label)
|
|
|
dino_max_x = dino_pos[1].max()
|
|
|
dino_min_y = dino_pos[0].max()
|
|
|
+ dino_max_y = dino_pos[0].min()
|
|
|
|
|
|
- coef = 1.2
|
|
|
+ coef = 1
|
|
|
trigger_second = (int(dino_pos[0].mean()), int(dino_max_x + int(coef*10)*pw))
|
|
|
+ trigger_feather = (dino_max_y, int(dino_max_x + int(coef*10)*pw))
|
|
|
trigger_first = (int(dino_pos[0].mean()), int(75*pw))
|
|
|
jumping = False
|
|
|
taking = False
|
|
|
+ laing = False
|
|
|
+
|
|
|
+ print(ph, pw)
|
|
|
|
|
|
start = time()
|
|
|
|
|
|
- cv2.imshow('View', rgbScreen)
|
|
|
+ if DEBUG: cv2.imshow('View', rgbScreen)
|
|
|
while cv2.waitKey(1) != ord('q'):
|
|
|
binScreen = take_binaryScreenshot(sct, playing_bbox)
|
|
|
binScreen = to_bbox(binScreen)
|
|
|
labels, labeledScreen = cv2.connectedComponents(binScreen.astype('uint8'))
|
|
|
|
|
|
- if not taking and not jumping and binScreen[trigger_second] != 0:
|
|
|
+ if not jumping and binScreen[trigger_second] != 0 or binScreen[trigger_feather] != 0:
|
|
|
print('jumping')
|
|
|
gui.keyDown('space')
|
|
|
jumping = True
|
|
|
|
|
|
- elif jumping and binScreen[trigger_second[0], trigger_second[1]-pw] == 0:
|
|
|
- print('landing')
|
|
|
+ elif jumping and binScreen[trigger_second[0], trigger_second[1]] == 0 and binScreen[trigger_feather[0], trigger_feather[1]] == 0:
|
|
|
+ print('taking')
|
|
|
gui.keyUp('space')
|
|
|
gui.keyDown('down')
|
|
|
jumping = False
|
|
|
taking = True
|
|
|
|
|
|
- elif taking and binScreen[dino_min_y, dino_max_x] != 0:
|
|
|
- print('landed')
|
|
|
+ if taking and binScreen[dino_max_y-ph, dino_max_x] != 0:
|
|
|
+ print('take off')
|
|
|
gui.keyUp('down')
|
|
|
taking = False
|
|
|
|
|
|
- if time() - start > 10:
|
|
|
+ if time() - start > 8:
|
|
|
print(time() - start)
|
|
|
coef += 0.1
|
|
|
trigger_second = (trigger_second[0], trigger_second[1]+pw)
|
|
|
+ trigger_feather = (trigger_feather[0], trigger_feather[1]+pw)
|
|
|
# trigger_first = (trigger_first[0], trigger_first[0]+int(pw))
|
|
|
start = time()
|
|
|
|
|
|
if DEBUG:
|
|
|
rgbScreen = binary_to_RGB(binScreen)
|
|
|
+ cv2.circle(rgbScreen, trigger_feather[::-1], radius=2, color=(255, 0, 0), thickness=2)
|
|
|
cv2.circle(rgbScreen, trigger_second[::-1], radius=2, color=(0, 255, 0), thickness=2)
|
|
|
cv2.circle(rgbScreen, trigger_first[::-1], radius=2, color=(0, 0, 255), thickness=2)
|
|
|
cv2.imshow('View', rgbScreen)
|