-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest accuracy with image.py
108 lines (72 loc) · 3.04 KB
/
test accuracy with image.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
import numpy as np
from PIL import ImageGrab
import cv2
import time
import win32api
from ctypes import windll # for dpi awareness to fix cursor wrong position issue under high dpi scaling
import os
import tensorflow as tf
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
import win32api, win32con
from screengrab import grab_screen
from VKhotkey import press , VK_CODE
lower_bound = np.array([30,30,0])
upper_bound = np.array([255,255,255])
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
fuckme = cv2.imread("test.png")
windll.user32.SetProcessDPIAware()
#RESTRICT VRAM
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
# Currently, memory growth needs to be the same across GPUs
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
logical_gpus = tf.config.experimental.list_logical_devices('GPU')
print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
except RuntimeError as e:
# Memory growth must be set before GPUs have been initialized
print(e)
#END OF RESTRICTION
model = load_model('sample.h5',compile = False)
counterclick= 0
clicktimechecker = 0
x, y = 3840//2 , 2160//2
print("Alive")
while(True):
# x,y = win32api.GetCursorPos()
# screengrab =
screengrab = np.array(grab_screen([x-250,y-250,x+250,y+250]))
# cv2.imshow('screen capture',cv2.cvtColor(np.array(gaa),cv2.COLOR_BGR2RGB)) # shows the window, but with RGB conversion
last_time = time.time()
# testing time
mask = cv2.inRange(cv2.cvtColor(screengrab, cv2.COLOR_BGR2HSV), lower_bound, upper_bound)
result_Frame = cv2.bitwise_and(cv2.cvtColor( screengrab,cv2.COLOR_BGR2RGB),cv2.cvtColor( screengrab,cv2.COLOR_BGR2RGB),mask=mask)
cur_image = image.img_to_array(fuckme)
cur_image = np.expand_dims(cur_image,axis=0)
# about 0.002 sec
result = model.predict(cur_image) # version 2 takes 0.005 to 0.006
print(result)
cv2.imshow("RESULT", fuckme)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
#print("time update : {} seconds".format(time.time() - last_time))
last_click_time = time.time() - clicktimechecker
Shift = win32api.GetAsyncKeyState((win32con.VK_SHIFT))
MouseB, MouseF = win32api.GetAsyncKeyState((win32con.VK_XBUTTON1)) , win32api.GetAsyncKeyState((win32con.VK_XBUTTON2))
if result == 0 and (MouseF != 0) and last_click_time > 0.1:
# print("CLICKED" + str(counterclick))
x,y = win32api.GetCursorPos()
click(x,y)
print("yea boi")
#press("ctrl") # add time clip to check so click doesn't go tooo fast
clicktimechecker = time.time()
cv2.imwrite("ClassifiedData/hit/"+str(time.time())+".png",result)
elif (result ==1) and (MouseF != 0) and last_click_time > 0.1:
cv2.imwrite("ClassifiedData/miss/"+str(time.time())+".png",result)
# print(last_click_time)