-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_GTchanges.py
151 lines (98 loc) · 7.08 KB
/
create_GTchanges.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import json
import numpy as np
from plyfile import PlyData,PlyElement
import sys
def retrievePoints(whereObjectIdnex,plydata):
resultsOfObject = np.asarray(whereObjectIdnex)
finalCoords = np.zeros((3,np.shape(resultsOfObject)[1]))
finalCoords = np.zeros((3,np.shape(resultsOfObject)[1]))
finalCoords = np.zeros((3,np.shape(resultsOfObject)[1]))
finalCoords[0][:] = plydata.elements[0].data['x'][resultsOfObject]
finalCoords[1][:] = plydata.elements[0].data['y'][resultsOfObject]
finalCoords[2][:] = plydata.elements[0].data['z'][resultsOfObject]
return finalCoords
with open('3RScan.json') as json_file:
data = json.load(json_file)
i = 0
for item in data:
if (item['type'] == 'validation'):
for data_item in item['scans']:
removed = np.asarray(data_item['removed'])
ref = item['reference']
dd = data_item['reference']
print ("Now Processing ",dd)
fR = open(sys.path[0] + '/' + dd + '/semseg.json')
fS = open(sys.path[0] + '/' + ref + '/semseg.json')
dataS = json.load(fS)
dataR = json.load(fR)
plydataS = PlyData.read(sys.path[0] + '/' + ref + '/labels.instances.annotated.ply')
plydataR = PlyData.read(sys.path[0] + '/' + dd + '/labels.instances.annotated.ply')
plydataRC = PlyData.read(sys.path[0] + '/' + dd + '/labels.instances.annotated.align.ply')
scan = plydataS.elements[0].data['objectId']
scan = scan.astype(np.int)
rescan = plydataR.elements[0].data['objectId']
rescan = rescan.astype(np.int)
finalCoordsSF = np.empty((3,0))
finalCoordsSR = np.empty((3,0))
scan = plydataS.elements[0].data['objectId']
scan = scan.astype(np.int)
rescan = plydataR.elements[0].data['objectId']
rescan = rescan.astype(np.int)
labelsS = np.empty((1,1),dtype=np.int)
labelsR = np.empty((1,1),dtype = np.int)
for i in dataS['segGroups']:
labelsS = np.vstack((labelsS,i['id']))
for i in dataR['segGroups']:
labelsR = np.vstack((labelsR,i['id']))
for changed in data_item['rigid']:
if changed['instance_reference']:
in_ref = np.asarray(changed['instance_reference'])
in_rescan = np.asarray(changed['instance_rescan'])
whereObjectIdnexS = np.where(scan == in_ref)
whereObjectIdnexR = np.where(rescan == in_rescan)
resultsOfObjectS = np.asarray(whereObjectIdnexS)
resultsOfObjectR = np.asarray(whereObjectIdnexR)
finalCoordsS = np.zeros((3,np.shape(resultsOfObjectS)[1]))
finalCoordsR = np.zeros((3,np.shape(resultsOfObjectR)[1]))
finalCoordsS[0][:] = plydataS.elements[0].data['x'][resultsOfObjectS]
finalCoordsS[1][:] = plydataS.elements[0].data['y'][resultsOfObjectS]
finalCoordsS[2][:] = plydataS.elements[0].data['z'][resultsOfObjectS]
finalCoordsR[0][:] = plydataRC.elements[0].data['x'][resultsOfObjectR]
finalCoordsR[1][:] = plydataRC.elements[0].data['y'][resultsOfObjectR]
finalCoordsR[2][:] = plydataRC.elements[0].data['z'][resultsOfObjectR]
finalCoordsSF = np.hstack((finalCoordsSF,finalCoordsS))
finalCoordsSR = np.hstack((finalCoordsSR,finalCoordsR))
if data_item['nonrigid']:
for changed in data_item['nonrigid']:
if changed not in removed:
in_ref = np.asarray(changed)
in_rescan = np.asarray(changed)
whereObjectIdnexS = np.where(scan == in_ref)
whereObjectIdnexR = np.where(rescan == in_rescan)
resultsOfObjectS = np.asarray(whereObjectIdnexS)
resultsOfObjectR = np.asarray(whereObjectIdnexR)
finalCoordsS = np.zeros((3,np.shape(resultsOfObjectS)[1]))
finalCoordsR = np.zeros((3,np.shape(resultsOfObjectR)[1]))
finalCoordsS[0][:] = plydataS.elements[0].data['x'][resultsOfObjectS]
finalCoordsS[1][:] = plydataS.elements[0].data['y'][resultsOfObjectS]
finalCoordsS[2][:] = plydataS.elements[0].data['z'][resultsOfObjectS]
finalCoordsR[0][:] = plydataRC.elements[0].data['x'][resultsOfObjectR]
finalCoordsR[1][:] = plydataRC.elements[0].data['y'][resultsOfObjectR]
finalCoordsR[2][:] = plydataRC.elements[0].data['z'][resultsOfObjectR]
finalCoordsSF = np.hstack((finalCoordsSF,finalCoordsS))
finalCoordsSR = np.hstack((finalCoordsSR,finalCoordsR))
#to check which objects have been added uncomment these lines
#for i in range(len(labelsS)):
# if labelsS[i] not in labelsR and labelsS[i] not in removed:
# #print (labelsS[i])
# whereObjectIdnexS = np.where(scan == labelsS[i])
# finalCoordsS = retrievePoints(whereObjectIdnexS,plydataS)
# finalCoordsSF = np.hstack((finalCoordsSF,finalCoordsS))
#for i in range(len(labelsR)):
# if labelsR[i] not in labelsS and labelsR[i] not in removed:
# whereObjectIdnexR = np.where(rescan == labelsR[i])
# finalCoordsR = retrievePoints(whereObjectIdnexR,plydataRC)
# finalCoordsSR = np.hstack((finalCoordsSR,finalCoordsR))
finalNonStaticPointsS = finalCoordsSF.transpose()
finalNonStaticPointsR = finalCoordsSR.transpose()
np.savetxt(sys.path[0] + '/' + dd + '/groundTruthChanged_withoutaddedobjects.xyz',finalNonStaticPointsR )