forked from UESTC-Ingress/IFSolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
118 lines (97 loc) · 3.1 KB
/
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
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
109
110
111
112
113
114
115
116
117
118
from multiprocessing.pool import ThreadPool
import cv2
from os import path, makedirs
import json
from FeatureFileUtils import *
from DownloadUtils import *
from CmpUtils import *
from GeoUtils import geo
from SplitUtils import *
from EntireCmpUtils import *
from GridUtils import *
def create_dir():
if not path.exists('data'):
os.makedirs('data')
if not path.exists('data_feature'):
os.makedirs('data_feature')
if not path.exists('data_feature_preview'):
os.makedirs('data_feature_preview')
if not path.exists('data_feature_sift'):
os.makedirs('data_feature_sift')
if not path.exists('data_feature_sift_preview'):
os.makedirs('data_feature_sift_preview')
if not path.exists('cmp'):
os.makedirs('cmp')
def main_download():
print("[IFSolver] Downloading latest intel package")
portal_list = getPortals("Portal_Export.csv")
run = ThreadPool(12).imap_unordered(fetch_url, portal_list)
for res in run:
if res != "":
print(res)
return portal_list
def main_features(portal_list, sift=False):
print("[IFSolver] Getting Features")
dlist = []
for portal in portal_list:
if sift:
_, d = get_sift_features(portal['id'])
else:
_, d = get_features(portal['id'])
dlist.append(d)
if not path.exists("ifs.jpg"):
print("[IFSolver] No IFS jpg found, exit")
exit()
return dlist
def main_split():
print("[IFSolver] Splitting Images")
img = cv2.imread('ifs.jpg', cv2.IMREAD_UNCHANGED)
if not path.exists("split.json"):
return split_img(img)
else:
with open('split.json') as json_file:
spl = json.load(json_file)
return split_img(img, pre=spl)
def main_fast_cmp(imgs, portal_list, dlist, imgpos):
ret = []
print("[IFSolver] Comparing pictures")
for idx, img in enumerate(imgs):
pname, lat, lng, valid = cmpImage(
img, dlist, portal_list)
ret.append({
"name": pname,
"lat": lat,
"lng": lng,
"valid": valid,
"pos": imgpos[idx]
})
return ret
def main_cmp(ifs_img, portal_list, dlist):
print("[IFSolver] Comparing pictures")
for idx, d in enumerate(dlist):
res = cmpEntireImage(
ifs_img, d, portal_list[idx])
def main_grid(portals):
rows = grid_judge(portals)
with open('result.json', 'w') as outfile:
json.dump(rows, outfile, ensure_ascii=False)
return rows
def main():
portal_list = main_download()
dlist = main_features(portal_list, sift=True)
img = cv2.imread('ifs.jpg', cv2.IMREAD_UNCHANGED)
main_cmp(img, portal_list, dlist)
def main_manual():
portal_list = main_download()
dlist = main_features(portal_list)
splitted_img, imgpos = main_split()
compared_portals = main_fast_cmp(splitted_img, portal_list, dlist, imgpos)
main_grid(compared_portals)
if __name__ == "__main__":
create_dir()
option = input("[IFSolver] Auto(y) or manual(n)?")
if option == 'y':
main()
else:
main_manual()
geo()