Mercurial Hosting > traffic-intelligence
changeset 612:6ee8765bb8db
minor modifications
author | MohamedGomaa |
---|---|
date | Thu, 04 Dec 2014 18:52:07 -0500 |
parents | 233867934190 |
children | 306db0f3c7a2 |
files | python/objectsmoothing.py |
diffstat | 1 files changed, 8 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/python/objectsmoothing.py Thu Dec 04 13:37:55 2014 -0500 +++ b/python/objectsmoothing.py Thu Dec 04 18:52:07 2014 -0500 @@ -13,13 +13,6 @@ 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: - if i.length>= minLengthParam*obj.length(): - featureList.append(i.num) - return featureList - def getFeatures(obj,features,featureID): #longestFeature = utils.argmaxDict({f:f.length() for i,f in enumerate(obj.features)}) t1,t3 = features[featureID].getFirstInstant(), features[featureID].getLastInstant() @@ -80,7 +73,7 @@ p1= object.getPositionAtInstant(i) p2= object.getPositionAtInstant(i+1) velocities[i]=p2-p1 - velocities[object.timeInterval.last]= velocities[object.timeInterval.last-1] # duplicate last point + velocities[object.getLastInstant()]= velocities[object.getLastInstant()-1] # duplicate last point if smoothing: velX= [velocities[y].aslist()[0] for y in sorted(velocities.keys())] velY= [velocities[y].aslist()[1] for y in sorted(velocities.keys())] @@ -121,7 +114,7 @@ t+= jerk[i]* jerk[i] return t -def getObject(obj,features,featureID,newNum,smoothing=False,halfWidth=3,create=False): +def smoothObjectTrajectory(obj,features,featureID,newNum,smoothing=False,halfWidth=3,create=False): results=[] bearing={} if create: @@ -131,7 +124,7 @@ for t in feature.getTimeInterval(): p1= feature.getPositionAtInstant(t) p2= obj.getPositionAtInstant(t) - if t!=feature.timeInterval.last: + if t!=feature.getLastInstant(): p3= feature.getPositionAtInstant(t+1) else: p1= feature.getPositionAtInstant(t-1) @@ -174,24 +167,22 @@ d1= translated[halfWidth]- feature.positions[halfWidth] d2= translated[-halfWidth-1]- feature.positions[-halfWidth-1] for i in xrange(halfWidth): - p1.x=feature.positions.__getitem__(i).x+d1.x - p2.x= feature.positions.__getitem__(-i-1).x+d2.x - p1.y=feature.positions.__getitem__(i).y+d1.y - p2.y= feature.positions.__getitem__(-i-1).y+d2.y + p1= feature.getPositionAt(i)+d1 + p2= feature.getPositionAt(-i-1)+d2 translated.setPosition(i,p1) translated.setPosition(-i-1,p2) - newObj= moving.MovingObject(newNum,timeInterval=feature.timeInterval,positions=translated) + newObj= moving.MovingObject(newNum,timeInterval=feature.getTimeInterval(),positions=translated) return newObj def smoothObjectTrajectory(obj,features,newNum,minLengthParam=0.7,smoothing=False,plotResults=True,halfWidth=3,computeVelocities=True,optimize=True,create=False): - featureList=FeatureList(obj,minLengthParam=minLengthParam) + featureList=[i.num for i in obj.features if i.length() >= minLengthParam*obj.length()] if featureList==[]: featureList.append(longestFeature(obj)) create=True objs=[] for featureID in featureList: - objTMP=getObject(obj,features,featureID,newNum,smoothing=smoothing,halfWidth=halfWidth,create=create) + objTMP=smoothObjectTrajectory(obj,features,featureID,newNum,smoothing=smoothing,halfWidth=halfWidth,create=create) objs.append(objTMP) newTranslated = moving.Trajectory() newInterval=[]