comparison trafficintelligence/moving.py @ 1283:77a310e29233

work on stationary objects
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 16 Jul 2024 12:06:34 -0400
parents 106365257da9
children 76f5693b530c
comparison
equal deleted inserted replaced
1282:106365257da9 1283:77a310e29233
51 return float(max(0,self.last-self.first)) 51 return float(max(0,self.last-self.first))
52 52
53 def equal(self, i2): 53 def equal(self, i2):
54 return self.first==i2.first and self.last == i2.last 54 return self.first==i2.first and self.last == i2.last
55 55
56 def getList(self): 56 def aslist(self):
57 return [self.first, self.last] 57 return [self.first, self.last]
58 58
59 def contains(self, instant): 59 def contains(self, instant):
60 return (self.first<=instant and self.last>=instant) 60 return (self.first<=instant and self.last>=instant)
61 61
1581 return obj 1581 return obj
1582 else: 1582 else:
1583 print('The object does not exist at {}'.format(inter)) 1583 print('The object does not exist at {}'.format(inter))
1584 return None 1584 return None
1585 1585
1586 def splitOverTime(self, instants, minObjectDuration = 1):
1587 '''Returns objects for each sub-time intervals:
1588 [first instant, t1], [t1+1, t2], [t2+1, t3], ... [tn, last instant]
1589 if duration more than minObjectDuration'''
1590 subObjects = []
1591 for t1, t2 in zip([self.getFirstInstant()-1]+instants, instants+[self.getLastInstant()]):
1592 if t2-t1-1 >= minObjectDuration:
1593 subObjects.append(self.getObjectInTimeInterval(TimeInterval(t1+1, t2)))
1594 return subObjects
1595
1586 def getObjectsInMask(self, mask, homography = None, minLength = 1): 1596 def getObjectsInMask(self, mask, homography = None, minLength = 1):
1587 '''Returns new objects made of the positions in the mask 1597 '''Returns new objects made of the positions in the mask
1588 mask is in the destination of the homography space''' 1598 mask is in the destination of the homography space'''
1589 if homography is not None: 1599 if homography is not None:
1590 self.projectedPositions = self.positions.homographyProject(homography) 1600 self.projectedPositions = self.positions.homographyProject(homography)
1839 return self.positions.getYCoordinates() 1849 return self.positions.getYCoordinates()
1840 1850
1841 def isStationary(self, speedThreshold, distanceThreshold): 1851 def isStationary(self, speedThreshold, distanceThreshold):
1842 '''Indicates if object is not moving 1852 '''Indicates if object is not moving
1843 if speed on average below threshold and final-initial position close enough 1853 if speed on average below threshold and final-initial position close enough
1844 1854 or the largest time interval during which the object is stationary (same condition)'''
1845 TODO: returns time interval stationary if starts moving or stops moving'''
1846 speeds = self.getSpeeds() 1855 speeds = self.getSpeeds()
1847 if quantile(speeds, 0.5) <= speedThreshold and Point.distanceNorm2(self.getPositionAt(0),self.getPositionAt(-1)) <= distanceThreshold: 1856 if quantile(speeds, 0.5) <= speedThreshold and Point.distanceNorm2(self.getPositionAt(0),self.getPositionAt(-1)) <= distanceThreshold:
1848 return True, None 1857 return True, None
1849 else: 1858 else:
1850 indices = flatnonzero(speeds < speedThreshold).tolist() 1859 indices = flatnonzero(speeds < speedThreshold).tolist()