Mercurial Hosting > traffic-intelligence
changeset 606:75ad9c0d6cc3
update the method to use multi featutes instead on single feature
author | MohamedGomaa |
---|---|
date | Mon, 24 Nov 2014 13:02:10 -0500 |
parents | 3550da215e7a |
children | 84690dfe5560 |
files | python/objectsmoothing.py |
diffstat | 1 files changed, 37 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/python/objectsmoothing.py Fri Nov 21 11:47:13 2014 -0500 +++ b/python/objectsmoothing.py Mon Nov 24 13:02:10 2014 -0500 @@ -12,6 +12,7 @@ else: dist[f]= moving.Point.distanceNorm2(feat.getPositionAtInstant(t-1),f.getPositionAtInstant(t)) return min(dist, key=dist.get) # = utils.argmaxDict(dist) + def FeatureList(obj,minLengthParam=0.7): featureList=[] for i in obj.features: @@ -70,68 +71,57 @@ angle2 = degrees(atan2(p2.y -p1.y, p2.x -p1.x)) bearing2 = (90 - angle2) % 360 dist= moving.Point.distanceNorm2(p1, p2) - return [dist,bearing1,bearing2,bearing2-bearing1] - -def computeSmoothVelocity (object,smoothing=True,halfWidth=3): - velocities=[[],[]] + return [dist,bearing1,bearing2,bearing2-bearing1] + +#Quantitative analysis "CSJ" functions +def computeVelocities (object,smoothing=True,halfWidth=3): #compute velocities from positions + velocities={} for i in list(object.timeInterval)[:-1]: p1= object.getPositionAtInstant(i) p2= object.getPositionAtInstant(i+1) - v=p2-p1 - velocities[0].append(v.x) - velocities[1].append(v.y) - velocities[0].append(v.x) # duplicate last point - velocities[1].append(v.y) + velocities[i]=p2-p1 + velocities[object.timeInterval.last]= velocities[object.timeInterval.last-1] # duplicate last point if smoothing: - v1= list(utils.filterMovingWindow(velocities[0], halfWidth)) - v2= list(utils.filterMovingWindow(velocities[1], halfWidth)) - velocities=[v1,v2] + velX= [velocities[y].aslist()[0] for y in sorted(velocities.keys())] + velY= [velocities[y].aslist()[1] for y in sorted(velocities.keys())] + v1= list(utils.filterMovingWindow(velX, halfWidth)) + v2= list(utils.filterMovingWindow(velY, halfWidth)) + smoothedVelocity={} + for t,i in enumerate(sorted(velocities.keys())): + smoothedVelocity[i]=moving.Point(v1[t], v2[t]) + velocities=smoothedVelocity return velocities -#Quantitative analysis "CSJ" functions -def computeVelocities (object): #compute velocities from positions TODO: combine with "computeSmoothVelocity" - speedMagnitude={} - speedVector={} - for i in list(object.timeInterval)[:-1]: - p1= object.getPositionAtInstant(i) - p2= object.getPositionAtInstant(i+1) - speedMagnitude[i]=(p2-p1).norm2() - speedVector[i]= p2-p1 - return speedMagnitude,speedVector - def computeAcceleration (object,fromPosition=True): - accMagnitude={} - accVector={} + acceleration={} if fromPosition: - tmp,sp=computeVelocities(object) - for i in sorted (sp.keys()): - if i != sorted (sp.keys())[-1]: - accMagnitude[i]= (sp[i+1]-sp[i]).norm2() - accVector[i]= sp[i+1]-sp[i] + velocities=computeVelocities(object,False,1) + for i in sorted (velocities.keys()): + if i != sorted (velocities.keys())[-1]: + acceleration[i]= velocities[i+1]-velocities[i] else: for i in list(object.timeInterval)[:-1]: v1= object.getVelocityAtInstant(i) v2= object.getVelocityAtInstant(i+1) - accMagnitude[i]=(v2-v1).norm2() - accVector[i]= v2-v1 - return accMagnitude,accVector + acceleration[i]= v2-v1 + return acceleration def computeJerk (object,fromPosition=True): jerk={} - tmp,acc=computeAcceleration (object,fromPosition=fromPosition) - for i in sorted (acc.keys()): - if i != sorted (acc.keys())[-1]: - jerk[i]= (acc[i+1]-acc[i]).norm2() + acceleration=computeAcceleration (object,fromPosition=fromPosition) + for i in sorted (acceleration.keys()): + if i != sorted (acceleration.keys())[-1]: + jerk[i]= (acceleration[i+1]-acceleration[i]).norm2() return jerk -def squaredSumJerk (object,fromPosition=True): +def sumSquaredJerk (object,fromPosition=True): jerk= computeJerk (object,fromPosition=fromPosition) t=0 for i in sorted(jerk.keys()): t+= jerk[i]* jerk[i] return t -def getObject(obj,features,featureID,newNum,smoothing=False,halfWidth=3,computeVelocities=True,create=False): +def getObject(obj,features,featureID,newNum,smoothing=False,halfWidth=3,create=False): results=[] bearing={} if create: @@ -201,7 +191,7 @@ create=True objs=[] for featureID in featureList: - objTMP=getObject(obj,features,featureID,newNum,smoothing=smoothing,halfWidth=halfWidth,computeVelocities=computeVelocities,create=create) + objTMP=getObject(obj,features,featureID,newNum,smoothing=smoothing,halfWidth=halfWidth,create=create) objs.append(objTMP) newTranslated = moving.Trajectory() newInterval=[] @@ -222,23 +212,22 @@ if computeVelocities: tmpTraj = moving.Trajectory() - velocities= computeSmoothVelocity(newObj,True,5) - for i in xrange(len(velocities[0])): - p=moving.Point(velocities[0][i], velocities[1][i]) - tmpTraj.addPosition(p) + velocities= computeVelocities(newObj,True,5) + for i in sorted(velocities.keys()): + tmpTraj.addPosition(velocities[i]) newObj.velocities=tmpTraj else: newObj.velocities=obj.velocities if optimize: - csj1= squaredSumJerk (obj,fromPosition=True) - csj2= squaredSumJerk (newObj,fromPosition=True) + csj1= sumSquaredJerk (obj,fromPosition=True) + csj2= sumSquaredJerk (newObj,fromPosition=True) if csj1<csj2: newObj=obj newObj.velocities=obj.velocities if computeVelocities and csj1>=csj2: - csj3= squaredSumJerk (obj,fromPosition=False) - csj4= squaredSumJerk (newObj,fromPosition=False) + csj3= sumSquaredJerk (obj,fromPosition=False) + csj4= sumSquaredJerk (newObj,fromPosition=False) if csj4<=csj3: newObj.velocities= obj.velocities newObj.featureNumbers=obj.featureNumbers