-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
50 lines (35 loc) · 1.19 KB
/
test.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
import cv2
import numpy as np
from mss import mss
from vision import Vision
from controller import Controller
from game import Game
print(mss().monitors)
vision = Vision()
controller = Controller()
#game = Game(vision, controller)
screenshot = cv2.imread('tests/screens/miners.png',cv2.IMREAD_COLOR)
x = cv2.cvtColor(screenshot, cv2.COLOR_BGR2HSV)
output = cv2.imread('tests/screens/miners.png')
threshold = 0.85
img_H, img_S, img_V = cv2.split(x)
template_HSV = cv2.cvtColor(vision.templates['enemy_freighter'], cv2.COLOR_BGR2HSV)
template_H, template_S, template_V = cv2.split(template_HSV)
resH = cv2.matchTemplate(img_H,template_H,cv2.TM_CCOEFF_NORMED)
res = resH
matches = np.where(res >= threshold)
#w, h = vision.templates['enemy_freighter'].shape[::-1]
w = 52
h= 55
#match = vision.find_template('enemy_freighter', image=x, threshold=0.8)
for pt in zip(*matches[::-1]):
cv2.rectangle(screenshot, pt, (pt[0] + w, pt[1] + h), (255,0,255), 2)
img = cv2.cvtColor(vision.templates['enemy_freighter'], cv2.COLOR_BGR2HSV)
name = "output"
cv2.namedWindow(name)
cv2.moveWindow(name, -3560,0)
cv2.imshow("baoo, ", img)
cv2.imshow(name,screenshot)
#game.run()
cv2.waitKey(0)
cv2.destroyAllWindows()