-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoiseRandomWalk.py
More file actions
242 lines (214 loc) · 8.09 KB
/
Copy pathnoiseRandomWalk.py
File metadata and controls
242 lines (214 loc) · 8.09 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
from random import randint
import os
from poseModel.Node import Node
from poseModel.Pose import Pose
from utils.personLoading import loadPersonOne, loadPersonTwo
from visualize import draw
# Change the parameters here
# the number of frame
# iter time
from utils.pose import createNewPose
from utils.Comparator import Comparator
frameNum = 50
iterationTime = 1
cameraHeight = 0
cameraDistance = 0
viewHeight = 1080
viewWidth = 1980
minSpeed = 4
maxSpeed = 14
walkingDirectionRange = [-10, 10]
personNum = 1
comparator = Comparator()
cwd = os.getcwd()
out2 = open(cwd + "/data/out2.txt", "w")
out3 = open(cwd + "/data/out3.txt", "w")
def createRandomNoise(currPose):
newPose = Pose()
for node in currPose.getPoseNodes():
newNode = Node(node.getID(), node.getX() / (1 + (50/node.getX())), node.getY() / (1 + (50/node.getY())), node.getConfidence())
newPose.addNode(newNode)
return newPose
def inputDataWithRandomOrder(currPoseList):
for i in range(0, personNum):
index = randint(0, len(currPoseList) - 1)
poseNodeList = []
if currPoseList[index].isNoiseExist():
poseNodeList = currPoseList[index].getNoisePoseNodes()
else:
poseNodeList = currPoseList[index].getPoseNodes()
for node in poseNodeList:
out2.write(str(node.getX()) + " " + str(node.getY()) + " ")
currPoseList.remove(currPoseList[index])
def inputDataWithIDOrder(currPoseList):
for i in range(0, personNum):
poseNodeList = []
if currPoseList[i].isNoiseExist():
poseNodeList = currPoseList[i].getNoisePoseNodes()
else:
poseNodeList = currPoseList[i].getPoseNodes()
for node in poseNodeList:
out2.write(str(node.getX()) + " " + str(node.getY()) + " ")
def inputDataWithSumOrder(currPoseList):
while len(currPoseList) != 0:
curSmallestDistPose = currPoseList[0]
for pose in currPoseList:
curSmallestDistPose = comparator.getSmallerDistancePose(pose, curSmallestDistPose)
for node in curSmallestDistPose.getPoseNodes():
out2.write(str(node.getX()) + " " + str(node.getY()) + " ")
currPoseList.remove(curSmallestDistPose)
def inputDataWithRankingOrder(currPoseList):
while len(currPoseList) != 0:
curSmallestDistPose = currPoseList[0]
for pose in currPoseList:
curSmallestDistPose = comparator.getSmallerRankingPose(pose, curSmallestDistPose)
poseNodeList = []
if curSmallestDistPose.isNoiseExist():
poseNodeList = curSmallestDistPose.getNoisePoseNodes()
else:
poseNodeList = curSmallestDistPose.getPoseNodes()
for node in poseNodeList:
out2.write(str(node.getX()) + " " + str(node.getY()) + " ")
currPoseList.remove(curSmallestDistPose)
def getOverlap(x1, y1, x2, y2, x3, y3, x4, y4):
dx = min(x2, x4) - max(x1, x3)
dy = min(y2, y4) - max(y1, y3)
if (dx >= 0) and (dy >= 0):
return dx * dy / (x2 - x1) * (y2 - y1)
else:
return -1
def checkOcclusion(currPose):
minX1, minY1, maxX1, maxY1 = currPose[0].getBound()
minX2, minY2, maxX2, maxY2 = currPose[1].getBound()
minX3, minY3, maxX3, maxY3 = currPose[2].getBound()
oAB = 0
oAC = 0
oBC = 0
if minX1 != -1:
oAB = getOverlap(minX1, minY1, maxX1, maxY1, minX2, minY2, maxX2, maxY2)
if minX2 != -1:
oAC = getOverlap(minX1, minY1, maxX1, maxY1, minX3, minY3, maxX3, maxY3)
if minX3 != -1:
oAC = getOverlap(minX2, minY2, maxX2, maxY2, minX3, minY3, maxX3, maxY3)
return oAB, oAC, oBC
def occlusion(currPose):
oAB, oAC, oBC = checkOcclusion(currPose)
if oAB != -1:
if oAC != -1 and oBC != -1:
currPose.remove(currPose[2])
currPose.remove(currPose[1])
else:
newPose = createNewPose(currPose[0], currPose[1])
currPose.remove(currPose[0])
currPose.remove(currPose[0])
currPose.append(newPose)
elif oAC != -1:
if oAB != -1 and oBC != -1:
currPose.remove(currPose[2])
currPose.remove(currPose[1])
else:
newPose = createNewPose(currPose[0], currPose[2])
currPose.remove(currPose[2])
currPose.remove(currPose[0])
currPose.append(newPose)
elif oBC != -1:
if oAC != -1 and oAB != -1:
currPose.remove(currPose[2])
currPose.remove(currPose[1])
else:
newPose = createNewPose(currPose[1], currPose[2])
currPose.remove(currPose[2])
currPose.remove(currPose[1])
currPose.append(newPose)
return currPose
def getRandomRange():
x = randint(walkingDirectionRange[0], walkingDirectionRange[1])
y = randint(walkingDirectionRange[0], walkingDirectionRange[1])
z = 0
if x > y:
z = x
x = y
y = z
return x, y
def run(f, i, cH, cD, vH, vW, minS, maxS, dirMin, dirMax, pNum):
global out2, out3
frameNum = int(f)
iterationTime = int(i)
cameraHeight = cH
cameraDistance = cD
viewHeight = vH
viewWidth = vW
minSpeed = minS
maxSpeed = maxS
walkingDirectionRange = [dirMin, dirMax]
personNum = int(pNum)
start_position = (0, 0)
box_width_height = (10, 10)
moving_speed = 10
gap = 1
randomX = 0
randomY = 360
# perform random walk
for j in range(0, iterationTime):
personList = []
for k in range(0, personNum):
newPerson = loadPersonOne(cwd, viewWidth, viewHeight, cameraHeight, cameraDistance)
newPerson.startFromEdge()
personList.append(newPerson)
for i in range(1, frameNum + int(frameNum/10) + 1):
currPoseList = []
# person 1
for person in personList:
speedOne = randint(minSpeed, maxSpeed)
direction = 0
if i % 20 == 0:
randX , randY = getRandomRange()
direction += randint(randX, randY)
person.walk(speedOne, direction)
currPose = person.getCurrentWalkingPose()
k = randint(0, 40)
if k >= 17 and k <= 27:
currPose.addNNDNoise()
elif k >= 28 and k <= 35:
currPose.addThirdNNDPose()
elif k >= 36 and k <= 38:
currPose.addHalfNNDPose()
elif k >= 39 and k <= 40:
currPose.addDNDNoise()
else:
pass
currPoseList.append(currPose)
minX, minY, maxX, maxY = currPose.getBound()
if minX < 0 or minY < 0 or maxX >= 1980 or maxY >= 1080:
out3.write("-1 -1 -1 -1 ")
# for n in currPoseList[0].getPoseNodes():
# n.invalid()
else:
# for i in range(0, personNum):
# for node in currPoseList[i].getPoseNodes():
# out3.write(str(node.getX()) + " " + str(node.getY()) + " ")
out3.write(str(minX) + " " + str(minY) + " " + str(maxX) + " " + str(maxY) + " ")
# specify the output file order
inputDataWithRankingOrder(currPoseList)
out2.write("\n")
out3.write("\n")
out2.close()
out3.close()
#inputData = open(cwd + "/data/inputData.txt", 'w')
#outputData = open(cwd + "/data/outputData.txt", 'w')
inputData = open("E:\mars\poseSimulatorData/input.txt", 'w')
outputData = open("E:\mars\poseSimulatorData/label.txt", 'w')
out2 = open(cwd + "/data/out2.txt", 'r')
out3 = open(cwd + "/data/out3.txt", 'r')
# this is for a bug in file operations, remove unrelated lines and spaces
for line in out2:
if line != "\n":
inputData.write(line)
for line in out3:
b = "100000 100000 -1 -1 " in line
if b == False:
outputData.write(line)
# ***********************************************************************
inputData.close()
outputData.close()
draw()