-
Notifications
You must be signed in to change notification settings - Fork 15
/
tests.py
143 lines (93 loc) · 3.3 KB
/
tests.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
import warnings
warnings.filterwarnings("ignore")
import os, sys
import cv2
import numpy as np
import pandas as pd
import time
import pyautogui
import win32gui
import win32api
import torch
from threading import Thread, Lock
from gamecapture import GameCapture
from detection import Detection
from vision import Vision
from utilities import Utilities
def main():
sw = pyautogui.size()[0] #win32api.GetSystemMetrics(0)
sh = pyautogui.size()[1] #win32api.GetSystemMetrics(0)
#Utilities.fps_test(sw, sh, 'Play - Stadia - Google Chrome')
filename = 'Battlefield4-0.mp4'
Utilities.process_video(filename)
filename = 'hitman3_dubia.mp4'
Utilities.process_video(filename)
filename = 'test0.mp4'
Utilities.process_video(filename)
#record_window('Play - Stadia - Google Chrome', 'out')
#single_frame_yolov5()
pass
def record_window(windowname, filename):
sw = pyautogui.size()[0] #win32api.GetSystemMetrics(0)
sh = pyautogui.size()[1] #win32api.GetSystemMetrics(0)
print(sw, sh)
cap = GameCapture(sw, sh, windowname, 'WIN32GUI')
win32gui.SetForegroundWindow( win32gui.FindWindow(None, windowname))
path = f"output\\{filename}.mp4"
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
#fps = Utilities.fps_test(sw, sh, 'Play - Stadia - Google Chrome')
fps = 52
writer = cv2.VideoWriter(path, fourcc, fps, (sw, sh))
start = time.time()
for _ in range(1800):
frame = cap.capture_frame()
writer.write(frame)
writer.release()
print(f'FPS: {1800/(time.time() - start)}')
def hsv_tool():
from hsvfilter import HsvFilter, HsvPannel
pannel = HsvPannel()
pannel.init_control_gui()
hsv_filter = HsvFilter(0, 180, 129, 15, 229, 243, 143, 0, 67, 0)
sw = pyautogui.size()[0]
sh = pyautogui.size()[1]
cap = GameCapture(sw/2, sh/2)
while True:
frame = cap.capture_frame_by_PIL()
hsv_filter = pannel.get_hsv_filter_from_controls()
frame = pannel.apply_hsv_filter(frame, hsv_filter)
cv2.imshow('Processed', frame)
if cv2.waitKey(1) == ord('q'):
cv2.destroyAllWindows()
break
def check_recording_fps():
pass
def mouse_positioning():
time.sleep(3)
pyautogui.moveTo(120, 120)
time.sleep(1)
pyautogui.moveTo(500, 500)
time.sleep(1)
pyautogui.moveTo(900, 500)
def single_frame_yolov5():
sw = pyautogui.size()[0] #win32api.GetSystemMetrics(0)
sh = pyautogui.size()[1] #win32api.GetSystemMetrics(0)
cap = GameCapture(sw, sh, 'Play - Stadia - Google Chrome', 'WIN32GUI')
vision = Vision()
time.sleep(3)
start = time.time()
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print(device)
#frame = cap.capture_frame()
frame = cv2.imread('data/warlock_fit2.png')
print(frame.shape)
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True).to(device)
results = model(frame)
print(f'Time: {time.time() - start}')
print(results.pred[0].tolist())
target = vision.get_priority_target(results.pred[0].tolist())
frame = vision.draw_bounding_boxes(frame, results.pred[0].tolist())
frame = vision.draw_crosshair(frame, target)
cv2.imwrite('output/single_frame_y5.png', frame)
if __name__ == '__main__':
main()