-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (32 loc) · 880 Bytes
/
main.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
import cv2
import sys
import numpy as np
img=~cv2.imread(sys.argv[1],cv2.IMREAD_GRAYSCALE)>>7
assert img.shape==(120,320)
result=""
cur=0
for i in range(img.shape[0]):
if not np.all(img[i]==0):
sparse=np.where(img[i])[0]
start,stop=sparse[0],sparse[-1]
step=-1 if cur>(start+stop)//2 else 1
if step==-1:
stop,start=start,stop
btn='DPAD_LEFT'
else:
btn='DPAD_RIGHT'
if cur>start:
result+='DPAD_LEFT 0.1s\n0.1s\n'*(cur-start)
else:
result+='DPAD_RIGHT 0.1s\n0.1s\n'*(start-cur)
for j in range(start,stop+step,step):
if img[i,j]:
result+='A 0.1s\n'
result+=f'{btn} 0.1s\n0.1s\n'
result+='A 0.1s\nDPAD_DOWN 0.1s\n0.1s\n'
cur=max(min(stop+step,320),0)
else:
result+='DPAD_DOWN 0.1s\n0.1s\n'
# with open(f'{sys.argv[1][:sys.argv[1].rfind(".")]}.txt','w') as f:
# f.write(result)
print(result)