Mercurial > hg > nsaunier > traffic-intelligence
comparison python/objectsmoothing.py @ 650:d74e8c175d6b
minor cleaning
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 16 Apr 2015 16:13:05 +0200 |
| parents | e54751e71d61 |
| children | dc70d9e711f5 |
comparison
equal
deleted
inserted
replaced
| 649:df9ddeaee4a6 | 650:d74e8c175d6b |
|---|---|
| 1 import storage, moving, utils | 1 import storage, moving, utils |
| 2 from math import * #atan2,asin,degrees,sin,cos,pi | 2 from math import atan2, degrees, sin, cos, pi |
| 3 import numpy as np | 3 from numpy import median |
| 4 | 4 |
| 5 import matplotlib.pyplot as plt | 5 import matplotlib.pyplot as plt |
| 6 | 6 |
| 7 def findNearest(feat, featureSet,t,reverse=True): | 7 def findNearest(feat, featureSet,t,reverse=True): |
| 8 dist={} | 8 dist={} |
| 65 bearing2 = (90 - angle2) % 360 | 65 bearing2 = (90 - angle2) % 360 |
| 66 dist= moving.Point.distanceNorm2(p1, p2) | 66 dist= moving.Point.distanceNorm2(p1, p2) |
| 67 return [dist,bearing1,bearing2,bearing2-bearing1] | 67 return [dist,bearing1,bearing2,bearing2-bearing1] |
| 68 | 68 |
| 69 #Quantitative analysis "CSJ" functions | 69 #Quantitative analysis "CSJ" functions |
| 70 def computeVelocities(obj,smoothing=True,halfWidth=3): #compute velocities from positions | 70 def computeVelocities(obj, smoothing=True, halfWidth=3): #compute velocities from positions |
| 71 velocities={} | 71 velocities={} |
| 72 for i in list(obj.timeInterval)[:-1]: | 72 for i in list(obj.timeInterval)[:-1]: |
| 73 p1= obj.getPositionAtInstant(i) | 73 p1= obj.getPositionAtInstant(i) |
| 74 p2= obj.getPositionAtInstant(i+1) | 74 p2= obj.getPositionAtInstant(i+1) |
| 75 velocities[i]=p2-p1 | 75 velocities[i]=p2-p1 |
| 130 p1= feature.getPositionAtInstant(t-1) | 130 p1= feature.getPositionAtInstant(t-1) |
| 131 p3= feature.getPositionAtInstant(t) | 131 p3= feature.getPositionAtInstant(t) |
| 132 bearing[t]= getBearing(p1,p2,p3)[1] | 132 bearing[t]= getBearing(p1,p2,p3)[1] |
| 133 results.append(getBearing(p1,p2,p3)) | 133 results.append(getBearing(p1,p2,p3)) |
| 134 | 134 |
| 135 medianResults=np.median(results,0) | 135 medianResults=median(results,0) |
| 136 dist= medianResults[0] | 136 dist= medianResults[0] |
| 137 angle= medianResults[3] | 137 angle= medianResults[3] |
| 138 | 138 |
| 139 for i in sorted(bearing.keys()): | 139 for i in sorted(bearing.keys()): |
| 140 bearing[i]= bearing[i]+angle | 140 bearing[i]= bearing[i]+angle |
| 202 if i.existsAtInstant(t): | 202 if i.existsAtInstant(t): |
| 203 p1= i.getPositionAtInstant(t) | 203 p1= i.getPositionAtInstant(t) |
| 204 xCoord.append(p1.x) | 204 xCoord.append(p1.x) |
| 205 yCoord.append(p1.y) | 205 yCoord.append(p1.y) |
| 206 if xCoord != []: | 206 if xCoord != []: |
| 207 tmp= moving.Point(np.median(xCoord),np.median(yCoord)) | 207 tmp= moving.Point(median(xCoord), median(yCoord)) |
| 208 newInterval.append(t) | 208 newInterval.append(t) |
| 209 newTranslated.addPosition(tmp) | 209 newTranslated.addPosition(tmp) |
| 210 | 210 |
| 211 newObj= moving.MovingObject(newNum, timeInterval = moving.TimeInterval(min(newInterval),max(newInterval)),positions=newTranslated) | 211 newObj= moving.MovingObject(newNum, timeInterval = moving.TimeInterval(min(newInterval),max(newInterval)),positions=newTranslated) |
| 212 | 212 |
