-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
62 lines (54 loc) · 1.65 KB
/
Copy pathutils.py
File metadata and controls
62 lines (54 loc) · 1.65 KB
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
room_label = [(0,'LivingRoom'),
(1,'MasterRoom'),
(2,'Kitchen'),
(3,'Bathroom'),
(4,'DiningRoom'),
(5,'ChildRoom'),
(6,'StudyRoom'),
(7,'SecondRoom'),
(8,'GuestRoom'),
(9,'Balcony'),
(10,'Entrance'),
(11,'Storage'),
(12,'Wall-in'),
(13,'External'),
(14,'ExteriorWall'),
(15,'FrontDoor'),
(16,'InteriorWall'),
(17,'InteriorDoor')]
category = [category for category in room_label if category[1] not in set(['External',\
'ExteriorWall','FrontDoor','InteriorWall','InteriorDoor'])]
num_category = len(category)
pixel2length = 18/256
def label2name(label=0):
if label < 0 or label > 17:
raise Exception("Invalid label!", label)
else:
return room_label[label][1]
def label2index(label=0):
if label < 0 or label > 17:
raise Exception("Invalid label!", label)
else:
return label
def index2label(index=0):
if index < 0 or index > 17:
raise Exception("Invalid index!", index)
else:
return index
def compute_centroid(mask):
sum_h = 0
sum_w = 0
count = 0
shape_array = mask.shape
for h in range(shape_array[0]):
for w in range(shape_array[1]):
if mask[h, w] != 0:
sum_h += h
sum_w += w
count += 1
return (sum_h//count, sum_w//count)
def log(file, msg='', is_print=True):
if is_print:
print(msg)
file.write(msg + '\n')
file.flush()