-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcan_parse_all.py
98 lines (77 loc) · 3.08 KB
/
can_parse_all.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
import sys
from scipy.ndimage import binary_hit_or_miss
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
from natsort import natsorted
from glob import glob
import json
from node import SplittingTree
from utils import make_rgb_indices, rplan_map
import networkx as nx
if __name__ == '__main__':
errors = {}
for jj in tqdm(range(316)):
IMG_PATH = f'/mnt/iscratch/datasets/rplan_ddg_var/{jj}/'
IMAGES = natsorted(glob(IMG_PATH + '*_nodoor.png'))
bads = []
graphs_consistent = []
for idx in tqdm(range(len(IMAGES)), leave=False):
with open(IMAGES[idx], 'rb') as fd:
img_pil = Image.open(fd)
img_np = np.asarray(img_pil)
img_idx = make_rgb_indices(img_np, rplan_map)
walls = img_idx == 1
structure1 = np.array([[0, 1], [1, 0]])
wall_corners = binary_hit_or_miss(walls, structure1=structure1)
img_idx[wall_corners] = 1
structure1 = np.array([[1, 0], [0, 1]])
wall_corners = binary_hit_or_miss(walls, structure1=structure1, origin1=(0, -1))
img_idx[wall_corners] = 1
try:
st = SplittingTree(img_idx, rplan_map, grad_from='whole')
st.create_tree()
st._merge_small_boxes(cross_wall=False)
st._merge_vert_boxes(cross_wall=False)
except Exception as e:
# raise(e)
# sys.exit()
bads.append(IMAGES[idx])
continue
horiz_adj = st.find_horiz_adj()
vert_adj = st.find_vert_adj()
# n_nodes = len(st.boxes)
# print('number of nodes,', n_nodes)
# print(f"{IMAGES[idx]}")
# for ii in range(n_nodes):
# for jj in range(ii):
# if ii == jj:
# continue
# else:
# truth = False
#
# # try with ii as source
# reachable_hii = nx.descendants(horiz_adj, ii)
# reachable_vii = nx.descendants(vert_adj, ii)
#
# reachable_ii = reachable_hii.union(reachable_vii)
#
# truth = truth or (jj in reachable_ii)
#
# # try with jj as source
# reachable_h = nx.descendants(horiz_adj, jj)
# reachable_v = nx.descendants(vert_adj, jj)
#
# reachable_jj = reachable_h.union(reachable_v)
#
# truth = truth or (ii in reachable_jj)
#
#
# if not truth:
# print(ii, reachable_hii, reachable_vii)
# print(jj, reachable_h, reachable_v, '\n--------------')
# sys.exit()
errors[jj] = bads
with open('lifull.json', 'w') as fp:
json.dump(errors, fp, indent=4)