-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosrs_main.py
89 lines (73 loc) · 2.46 KB
/
osrs_main.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
import cv2 as cv
from time import sleep
from time import time
from window_capture import WindowCapture
from vision import ItemVision
import pyautogui
from rng import NumGen
from threading import Thread
from detection import Detection
DEBUG = True
# Init window capture class
wincap = WindowCapture('RuneLite - Too Run 2200')
checking_exp = False
rng = NumGen()
# load trained model
#cascade_skills = cv.CascadeClassifier('data/cascade/cascade.xml')
#assert not cascade_skills.empty()
# load empty Vision class
vision = ItemVision(None)
#vision_skills = ItemVision('images/skill_icon.jpg')
vision_total_level = ItemVision('images/total_level.jpg')
# load detector
detector = Detection('images/skill_icon.jpg')
def check_total_lvl_exp(rectangles):
# Do actions
if len(rectangles) > 0:
# Click on skills icon7
targets = vision.get_click_points(rectangles)
target = wincap.get_screen_pos(targets[0])
pyautogui.moveTo(x=target[0], y=target[1], duration=rng.mouseMoveSpeed(), tween=rng.tweenType()) # over norm distrib seconds move in a random method
rng.leftClick()
sleep(5)
global checking_exp
checking_exp = False
wincap.start()
detector.start()
# Start timer
loop_time = time()
while True:
# If we dont have a screenshot dont run code below this point
if wincap.screenshot is None:
continue
# Do the object detection (Ai)
#rectangles = cascade_skills.detectMultiScale(screenshot)
# Give detector current screenshot
detector.update(wincap.screenshot)
# Non Ai
rectangles1 = vision_total_level.find(wincap.screenshot, 0.75)
if DEBUG:
# Draw rectangles on original image
detection_image = vision.draw_rectangles(wincap.screenshot, detector.rectangles)
# Display final image
cv.imshow('Game', detection_image)
# Start action thread
if not checking_exp:
checking_exp = True
t = Thread(target=check_total_lvl_exp, args=(detector.rectangles,))
t.start()
# Count FPS
print('FPS {}'.format(1 / (time() - loop_time)))
loop_time = time()
# Wait for 1ms to see if q pressed
key = cv.waitKey(1)
if key == ord('q'):
detector.stop()
wincap.stop()
cv.destroyAllWindows()
break
#elif key == ord('p'):
# cv.imwrite('data/positive/{}.jpg'.format(loop_time), screenshot)
#elif key == ord('n'):
# cv.imwrite('data/negative/{}.jpg'.format(loop_time), screenshot)
print('done')