nsaunier/traffic-intelligence
work on stationary objects
Commit 77a310e29233 · Nicolas Saunier · 2024-07-16 12:06 -0400
Comments
No comments yet.
Diff
diff --git a/trafficintelligence/moving.py b/trafficintelligence/moving.py
--- a/trafficintelligence/moving.py
+++ b/trafficintelligence/moving.py
@@ -53,7 +53,7 @@
def equal(self, i2):
return self.first==i2.first and self.last == i2.last
- def getList(self):
+ def aslist(self):
return [self.first, self.last]
def contains(self, instant):
@@ -1583,6 +1583,16 @@
print('The object does not exist at {}'.format(inter))
return None
+ def splitOverTime(self, instants, minObjectDuration = 1):
+ '''Returns objects for each sub-time intervals:
+ [first instant, t1], [t1+1, t2], [t2+1, t3], ... [tn, last instant]
+ if duration more than minObjectDuration'''
+ subObjects = []
+ for t1, t2 in zip([self.getFirstInstant()-1]+instants, instants+[self.getLastInstant()]):
+ if t2-t1-1 >= minObjectDuration:
+ subObjects.append(self.getObjectInTimeInterval(TimeInterval(t1+1, t2)))
+ return subObjects
+
def getObjectsInMask(self, mask, homography = None, minLength = 1):
'''Returns new objects made of the positions in the mask
mask is in the destination of the homography space'''
@@ -1841,8 +1851,7 @@
def isStationary(self, speedThreshold, distanceThreshold):
'''Indicates if object is not moving
if speed on average below threshold and final-initial position close enough
-
- TODO: returns time interval stationary if starts moving or stops moving'''
+ or the largest time interval during which the object is stationary (same condition)'''
speeds = self.getSpeeds()
if quantile(speeds, 0.5) <= speedThreshold and Point.distanceNorm2(self.getPositionAt(0),self.getPositionAt(-1)) <= distanceThreshold:
return True, None