Mercurial Hosting > traffic-intelligence
annotate python/objectsmoothing.py @ 652:3b13ec964476
removed useless and buggy code
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 24 Apr 2015 17:02:47 +0200 |
parents | d74e8c175d6b |
children | dc70d9e711f5 |
rev | line source |
---|---|
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
1 import storage, moving, utils |
650
d74e8c175d6b
minor cleaning
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
644
diff
changeset
|
2 from math import atan2, degrees, sin, cos, pi |
d74e8c175d6b
minor cleaning
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
644
diff
changeset
|
3 from numpy import median |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
4 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
5 import matplotlib.pyplot as plt |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
6 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
7 def findNearest(feat, featureSet,t,reverse=True): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
8 dist={} |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
9 for f in featureSet: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
10 if reverse: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
11 dist[f]= moving.Point.distanceNorm2(feat.getPositionAtInstant(t+1),f.getPositionAtInstant(t)) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
12 else: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
13 dist[f]= moving.Point.distanceNorm2(feat.getPositionAtInstant(t-1),f.getPositionAtInstant(t)) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
14 return min(dist, key=dist.get) # = utils.argmaxDict(dist) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
15 |
644 | 16 def getFeatures(obj, featureID): |
17 first = obj.features[featureID].getFirstInstant() | |
18 last = obj.features[featureID].getLastInstant() | |
19 featureList=[[obj.features[featureID],first,last,moving.Point(0,0)]] | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
20 # find the features to fill in the beginning of the object existence |
644 | 21 currentFeature = obj.features[featureID] |
22 while first != obj.getFirstInstant(): | |
23 delta=featureList[-1][3] | |
24 featureSet = [f for f in obj.features if f.existsAtInstant(first-1)] | |
25 feat = findNearest(currentFeature,featureSet,first-1,reverse=True) | |
26 if feat.existsAtInstant(first): | |
27 featureList.append([feat,feat.getFirstInstant(),first-1,(currentFeature.getPositionAtInstant(first)-feat.getPositionAtInstant(first))+delta]) | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
28 else: |
644 | 29 featureList.append([feat,feat.getFirstInstant(),first-1,(currentFeature.getPositionAtInstant(first)-feat.getPositionAtInstant(first-1))+delta]) |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
30 currentFeature = feat |
644 | 31 first= feat.getFirstInstant() |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
32 # find the features to fill in the end of the object existence |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
33 delta=moving.Point(0,0) |
644 | 34 currentFeature = obj.features[featureID] |
35 while last!= obj.getLastInstant(): | |
36 featureSet = [f for f in obj.features if f.existsAtInstant(last+1)] | |
37 feat = findNearest(currentFeature,featureSet,last+1,reverse=False) | |
38 if feat.existsAtInstant(last): | |
39 featureList.append([feat,last+1,feat.getLastInstant(),(currentFeature.getPositionAtInstant(last)-feat.getPositionAtInstant(last))+delta]) | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
40 else: |
644 | 41 featureList.append([feat,last+1,feat.getLastInstant(),(currentFeature.getPositionAtInstant(last)-feat.getPositionAtInstant(last+1))+delta]) |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
42 currentFeature = feat |
644 | 43 last= feat.getLastInstant() |
44 delta=featureList[-1][3] | |
45 return featureList | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
46 |
644 | 47 def buildFeature(obj, featureID, num = 1): |
48 featureList= getFeatures(obj, featureID) | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
49 tmp={} |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
50 delta={} |
644 | 51 for i in featureList: |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
52 for t in xrange(i[1],i[2]+1): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
53 tmp[t]=[i[0],i[3]] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
54 newTraj = moving.Trajectory() |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
55 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
56 for instant in obj.getTimeInterval(): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
57 newTraj.addPosition(tmp[instant][0].getPositionAtInstant(instant)+tmp[instant][1]) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
58 newFeature= moving.MovingObject(num,timeInterval=obj.getTimeInterval(),positions=newTraj) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
59 return newFeature |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
60 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
61 def getBearing(p1,p2,p3): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
62 angle = degrees(atan2(p3.y -p1.y, p3.x -p1.x)) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
63 bearing1 = (90 - angle) % 360 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
64 angle2 = degrees(atan2(p2.y -p1.y, p2.x -p1.x)) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
65 bearing2 = (90 - angle2) % 360 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
66 dist= moving.Point.distanceNorm2(p1, p2) |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
67 return [dist,bearing1,bearing2,bearing2-bearing1] |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
68 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
69 #Quantitative analysis "CSJ" functions |
650
d74e8c175d6b
minor cleaning
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
644
diff
changeset
|
70 def computeVelocities(obj, smoothing=True, halfWidth=3): #compute velocities from positions |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
71 velocities={} |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
72 for i in list(obj.timeInterval)[:-1]: |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
73 p1= obj.getPositionAtInstant(i) |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
74 p2= obj.getPositionAtInstant(i+1) |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
75 velocities[i]=p2-p1 |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
76 velocities[obj.getLastInstant()]= velocities[obj.getLastInstant()-1] # duplicate last point |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
77 if smoothing: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
78 velX= [velocities[y].aslist()[0] for y in sorted(velocities.keys())] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
79 velY= [velocities[y].aslist()[1] for y in sorted(velocities.keys())] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
80 v1= list(utils.filterMovingWindow(velX, halfWidth)) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
81 v2= list(utils.filterMovingWindow(velY, halfWidth)) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
82 smoothedVelocity={} |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
83 for t,i in enumerate(sorted(velocities.keys())): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
84 smoothedVelocity[i]=moving.Point(v1[t], v2[t]) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
85 velocities=smoothedVelocity |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
86 return velocities |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
87 |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
88 def computeAcceleration(obj,fromPosition=True): |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
89 acceleration={} |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
90 if fromPosition: |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
91 velocities=computeVelocities(obj,False,1) |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
92 for i in sorted(velocities.keys()): |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
93 if i != sorted(velocities.keys())[-1]: |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
94 acceleration[i]= velocities[i+1]-velocities[i] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
95 else: |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
96 for i in list(obj.timeInterval)[:-1]: |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
97 v1= obj.getVelocityAtInstant(i) |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
98 v2= obj.getVelocityAtInstant(i+1) |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
99 acceleration[i]= v2-v1 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
100 return acceleration |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
101 |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
102 def computeJerk(obj,fromPosition=True): |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
103 jerk={} |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
104 acceleration=computeAcceleration(obj,fromPosition=fromPosition) |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
105 for i in sorted(acceleration.keys()): |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
106 if i != sorted(acceleration.keys())[-1]: |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
107 jerk[i] = (acceleration[i+1]-acceleration[i]).norm2() |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
108 return jerk |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
109 |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
110 def sumSquaredJerk(obj,fromPosition=True): |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
111 jerk= computeJerk(obj,fromPosition=fromPosition) |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
112 t=0 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
113 for i in sorted(jerk.keys()): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
114 t+= jerk[i]* jerk[i] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
115 return t |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
116 |
644 | 117 def smoothObjectTrajectory(obj, featureID,newNum,smoothing=False,halfWidth=3,create=False): |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
118 results=[] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
119 bearing={} |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
120 if create: |
644 | 121 feature = buildFeature(obj, featureID , num=1) # why num=1 |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
122 else: |
644 | 123 feature = obj.features[featureID] |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
124 for t in feature.getTimeInterval(): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
125 p1= feature.getPositionAtInstant(t) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
126 p2= obj.getPositionAtInstant(t) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
127 if t!=feature.getLastInstant(): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
128 p3= feature.getPositionAtInstant(t+1) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
129 else: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
130 p1= feature.getPositionAtInstant(t-1) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
131 p3= feature.getPositionAtInstant(t) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
132 bearing[t]= getBearing(p1,p2,p3)[1] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
133 results.append(getBearing(p1,p2,p3)) |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
134 |
650
d74e8c175d6b
minor cleaning
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
644
diff
changeset
|
135 medianResults=median(results,0) |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
136 dist= medianResults[0] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
137 angle= medianResults[3] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
138 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
139 for i in sorted(bearing.keys()): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
140 bearing[i]= bearing[i]+angle |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
141 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
142 if smoothing: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
143 bearingInput=[] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
144 for i in sorted(bearing.keys()): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
145 bearingInput.append(bearing[i]) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
146 import utils |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
147 bearingOut=utils.filterMovingWindow(bearingInput, halfWidth) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
148 for t,i in enumerate(sorted(bearing.keys())): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
149 bearing[i]=bearingOut[t] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
150 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
151 #solve a smoothing problem in case of big drop in computing bearing (0,360) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
152 for t,i in enumerate(sorted(bearing.keys())): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
153 if i!= max(bearing.keys()) and abs(bearingInput[t] - bearingInput[t+1])>=340: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
154 for x in xrange(max(i-halfWidth,min(bearing.keys())),min(i+halfWidth,max(bearing.keys()))+1): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
155 bearing[x]=bearingInput[t-i+x] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
156 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
157 translated = moving.Trajectory() |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
158 for t in feature.getTimeInterval(): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
159 p1= feature.getPositionAtInstant(t) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
160 p1.x = p1.x + dist*sin(bearing[t]*pi/180) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
161 p1.y = p1.y + dist*cos(bearing[t]*pi/180) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
162 translated.addPosition(p1) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
163 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
164 #modify first and last un-smoothed positions (half width) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
165 if smoothing: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
166 d1= translated[halfWidth]- feature.positions[halfWidth] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
167 d2= translated[-halfWidth-1]- feature.positions[-halfWidth-1] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
168 for i in xrange(halfWidth): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
169 p1= feature.getPositionAt(i)+d1 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
170 p2= feature.getPositionAt(-i-1)+d2 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
171 translated.setPosition(i,p1) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
172 translated.setPosition(-i-1,p2) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
173 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
174 newObj= moving.MovingObject(newNum,timeInterval=feature.getTimeInterval(),positions=translated) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
175 return newObj |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
176 |
644 | 177 def smoothObject(obj, newNum, minLengthParam = 0.7, smoothing = False, plotResults = True, halfWidth = 3, _computeVelocities = True, optimize = True, create = False): |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
178 '''Computes a smoother trajectory for the object |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
179 and optionnally smoother velocities |
644 | 180 |
181 The object should have its features in obj.features | |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
182 TODO: check whether features are necessary''' |
644 | 183 if len(obj.features) == 0: |
184 print('Object {} has an empty list of features: please load and add them using obj.setFeatures(features)'.format(obj.getNum())) | |
185 from sys import exit | |
186 exit() | |
187 | |
188 featureList=[i for i,f in enumerate(obj.features) if f.length() >= minLengthParam*obj.length()] | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
189 if featureList==[]: |
644 | 190 featureList.append(utils.argmaxDict({i:f.length() for i,f in enumerate(obj.features)})) |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
191 create = True |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
192 newObjects = [] |
644 | 193 for featureID in featureList: # featureID should be the index in the list of obj.features |
194 newObjects.append(smoothObjectTrajectory(obj, featureID, newNum, smoothing = smoothing, halfWidth = halfWidth, create = create)) | |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
195 |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
196 newTranslated = moving.Trajectory() |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
197 newInterval = [] |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
198 for t in obj.getTimeInterval(): |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
199 xCoord=[] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
200 yCoord=[] |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
201 for i in newObjects: |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
202 if i.existsAtInstant(t): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
203 p1= i.getPositionAtInstant(t) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
204 xCoord.append(p1.x) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
205 yCoord.append(p1.y) |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
206 if xCoord != []: |
650
d74e8c175d6b
minor cleaning
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
644
diff
changeset
|
207 tmp= moving.Point(median(xCoord), median(yCoord)) |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
208 newInterval.append(t) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
209 newTranslated.addPosition(tmp) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
210 |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
211 newObj= moving.MovingObject(newNum, timeInterval = moving.TimeInterval(min(newInterval),max(newInterval)),positions=newTranslated) |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
212 |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
213 if _computeVelocities: |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
214 tmpTraj = moving.Trajectory() |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
215 velocities= computeVelocities(newObj,True,5) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
216 for i in sorted(velocities.keys()): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
217 tmpTraj.addPosition(velocities[i]) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
218 newObj.velocities=tmpTraj |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
219 else: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
220 newObj.velocities=obj.velocities |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
221 |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
222 if optimize: |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
223 csj1= sumSquaredJerk(obj,fromPosition=True) |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
224 csj2= sumSquaredJerk(newObj,fromPosition=True) |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
225 if csj1<csj2: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
226 newObj=obj |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
227 newObj.velocities=obj.velocities |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
228 if _computeVelocities and csj1>=csj2: |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
229 csj3= sumSquaredJerk(obj,fromPosition=False) |
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
230 csj4= sumSquaredJerk(newObj,fromPosition=False) |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
231 if csj4<=csj3: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
232 newObj.velocities= obj.velocities |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
233 |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
234 newObj.featureNumbers=obj.featureNumbers |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
235 newObj.features=obj.features |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
236 newObj.userType=obj.userType |
641
9fe254f11743
cleaning under way and renaming
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
237 |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
238 if plotResults: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
239 plt.figure() |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
240 plt.title('objects_id = {}'.format(obj.num)) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
241 for i in featureList: |
644 | 242 obj.features[i].plot('cx-') |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
243 obj.plot('rx-') |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
244 newObj.plot('gx-') |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
612
diff
changeset
|
245 return newObj |