-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestview.py
More file actions
42 lines (30 loc) · 800 Bytes
/
testview.py
File metadata and controls
42 lines (30 loc) · 800 Bytes
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
import cv2
import numpy as np
from env import ExampleEnv, BGR_COLORMAP
SIZE = (8, 8) # W, H
WIN_SIZE = (800, 800) # W, H
KEY_MAP = {
ord('w'): 0,
ord('s'): 1,
ord('a'): 2,
ord('d'): 3,
}
def render():
img = np.zeros((SIZE[1], SIZE[0], 3), dtype=np.uint8)
for cls_idx, color in BGR_COLORMAP.items():
mask = env.state[cls_idx] == 1.0
img[mask] = color
img = cv2.resize(img, WIN_SIZE, interpolation=cv2.INTER_NEAREST)
return img
env = ExampleEnv(*SIZE)
while True:
cv2.imshow("Example Env", render())
key = cv2.waitKey(0) & 0xFF # 0 fps (waits for input)
if key == 27: # esc
break
elif key == ord('r'):
env.reset()
continue
elif key in KEY_MAP:
env.step(KEY_MAP[key])
cv2.destroyAllWindows()