-
Notifications
You must be signed in to change notification settings - Fork 10
/
NetworkDataCollection.py
83 lines (69 loc) · 2.92 KB
/
NetworkDataCollection.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
import pyautogui
import numpy as np
from datetime import datetime
from datetime import timedelta
import tensorflow.keras as keras
import ctypes
import uuid
# Find Center Of Screen
user32 = ctypes.windll.user32
screenSize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
centerPoint = tuple(i/2 for i in screenSize)
print('Screen Size X:%d y:%d' % screenSize)
print('Targeting Center X:%d y:%d' % centerPoint)
# 4K Check
fourKMultiplier = 1
if screenSize[0] == 3840:
fourKMultiplier = 2
elif screenSize[0] == 1920:
fourKMultiplier = 1
else:
raise Exception('Invalid Screen Resolution', 'Set up your screen resolution')
lastSecondTimestamp = datetime.utcnow() + timedelta(seconds=1)
tickCounter = 0
# Load Model
model = keras.models.load_model('..\\Models\\CODV7.h5')
# Starting Main Loop (will run faster if using Tensorflow + GPU)
print('Started Inner Loop')
while True:
tickCounter += 1
if datetime.utcnow() > lastSecondTimestamp:
lastSecondTimestamp = datetime.utcnow() + timedelta(seconds=1)
print('Ticks Per Second %d' % tickCounter)
tickCounter = 0
# Grab Screen
image = pyautogui.screenshot(region=(centerPoint[0] - (100 * fourKMultiplier),
centerPoint[1] - (100 * fourKMultiplier),
(200 * fourKMultiplier), (200 * fourKMultiplier)))
if image.size != (200, 200):
image = image.resize((200, 200), 0)
# Format and Normalize Data
normalizedImage = np.asarray([np.asarray(image)]) / 255
# Predict
prediction = model.predict(normalizedImage)
targetFolder = None
if prediction[0][0] == 1 and (1 == 1):
targetFolder = '\\100\\'
elif prediction[0][0] > .90 and prediction[0][0] < 100 and (1 == 1):
targetFolder = '\\90-99\\'
elif prediction[0][0] > .80 and prediction[0][0] < .90 and (1 == 1):
targetFolder = '\\80-89\\'
elif prediction[0][0] > .70 and prediction[0][0] < .80 and (1 == 1):
targetFolder = '\\70-79\\'
elif prediction[0][0] > .60 and prediction[0][0] < .70 and (1 == 1):
targetFolder = '\\60-69\\'
elif prediction[0][0] > .50 and prediction[0][0] < .60 and (1 == 1):
targetFolder = '\\50-59\\'
elif prediction[0][0] > .40 and prediction[0][0] < .50 and (1 == 1):
targetFolder = '\\40-49\\'
elif prediction[0][0] > .30 and prediction[0][0] < .40 and (1 == 1):
targetFolder = '\\30-39\\'
elif prediction[0][0] > .20 and prediction[0][0] < .30 and (1 == 1):
targetFolder = '\\20-29\\'
elif prediction[0][0] > .10 and prediction[0][0] < .20 and (1 == 1):
targetFolder = '\\10-19\\'
if targetFolder is not None:
baseDirectory = 'G:\\Projects\\COD Target Trainer\\Data Collection'
generatedGUID = str(uuid.uuid1())
image.save(baseDirectory + targetFolder + generatedGUID + '.png', 'png')
print('Writing %' + str((prediction[0][0] * 100)))