-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomWalk.py
171 lines (151 loc) · 5.22 KB
/
randomWalk.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from random import randint
import os
from poseModel.Pose import Pose
from utils.personLoading import loadPersonOne, loadPersonTwo
# Change the parameters here
# the number of frame
# iter time
from utils.pose import createNewPose
frameNum = 50
iterationTime = 1
cameraHeight = 100
cameraDistance = 100
viewHeight = 1080
viewWidth = 1980
minSpeed = 10
maxSpeed = 20
walkingDirectionRange = [-90, 450]
personNum = 3
cwd = os.getcwd()
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
# frameNum = 50
# iterationTime = 1
# cameraHeight = 100
# cameraDistance = 100
# viewHeight = 1080
# viewWidth = 1980
# minSpeed = 10
# maxSpeed = 20
# walkingDirectionRange = [-90, 450]
# personNum = 3
def run(f, i, cH, cD, vH, vW, minS, maxS, dirMin, dirMax, pNum):
frameNum = int(f)
iterationTime = int(i)
cameraHeight = cH
cameraDistance = cD
viewHeight = vH
viewWidth = vW
minSpeed = minS
maxSpeed = maxS
walkingDirectionRange = [dirMin, dirMax]
personNum = int(pNum)
out2 = open(cwd + "/data/out2.txt", "w")
out3 = open(cwd + "/data/out3.txt", "w")
# perform random walk
for j in range(0, iterationTime):
personList = []
for k in range(0, personNum):
newPerson = loadPersonOne(cwd, viewWidth, viewHeight)
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 = randint(0, 360)
if i % 10 == 0:
randX , randY = getRandomRange()
direction += randint(randX, randY)
person.walk(speedOne, direction)
currPose = person.getCurrentWalkingPose()
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:
out3.write(str(minX) + " " + str(minY) + " " + str(maxX) + " " + str(maxY) + " ")
for i in range(0, personNum):
index = randint(0, len(currPoseList)-1)
for node in currPoseList[index].getPoseNodes():
out2.write(str(node.getX()) + " " + str(node.getY()) + " ")
currPoseList.remove(currPoseList[index])
out2.write("\n")
out3.write("\n")
out2.close()
out3.close()
inputData = open(cwd + "/data/inputData.txt", 'w')
outputData = open(cwd + "/data/outputData.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()