-
Notifications
You must be signed in to change notification settings - Fork 4
/
make_np_savez.py
74 lines (60 loc) · 1.99 KB
/
make_np_savez.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
#!/usr/bin/env python3
# make background.npz
import os
import cv2
import numpy as np
import urllib.request
from fgosccnt import img_hist
aadb_url = "https://raw.githubusercontent.com/atlasacademy/aa-db/master/build/assets/list/"
img_dir = "data/misc/"
gold_flame = img_dir + "listframes3_bg.png"
silver_flame = img_dir + "listframes2_bg.png"
bronze_flame = img_dir + "listframes1_bg.png"
zero_flame = img_dir + "listframes0_bg.png"
file_gold = "data/misc/gold.png"
file_silver = "data/misc/silver.png"
file_bronze = "data/misc/bronze.png"
file_zero = "data/misc/zero.png"
output = "background.npz"
# 余白を落して拡大して保存
def download_file(url, filename):
try:
with urllib.request.urlopen(url + filename) as web_file:
data = web_file.read()
with open(img_dir + filename, mode='wb') as local_file:
local_file.write(data)
except urllib.error.URLError as e:
print(e)
def makeimg(file):
img = cv2.imread(file)
h, w = img.shape[:2]
img = img[5: h-5, 5: w-5]
#横幅188に拡大
SIZE = 188
img = cv2.resize(img, (0, 0),
fx=SIZE/(w - 10), fy=SIZE/(w - 10),
interpolation=cv2.INTER_AREA)
return img
def main():
for i in range(4):
download_file(aadb_url, "listframes" + str(i) + "_bg.png")
img_zero = makeimg(zero_flame)
img_zero = img_zero[30:119, 7:25]
hist_zero = img_hist(img_zero)
img_gold = makeimg(gold_flame)
img_gold = img_gold[30:119, 7:25]
hist_gold = img_hist(img_gold)
img_silver = makeimg(silver_flame)
img_silver = img_silver[30:119, 7:25]
hist_silver = img_hist(img_silver)
img_bronze = makeimg(bronze_flame)
img_bronze = img_bronze[30:119, 7:25]
hist_bronze = img_hist(img_bronze)
np.savez(output,
hist_zero=hist_zero,
hist_gold=hist_gold,
hist_silver=hist_silver,
hist_bronze=hist_bronze)
if __name__ == '__main__':
os.makedirs(img_dir, exist_ok=True)
main()