nsaunier/traffic-intelligence
minor modifications
Commit 0f5bebd62a55 · Nicolas Saunier · 2024-05-24 16:15 -0400
Comments
No comments yet.
Diff
diff --git a/scripts/dltrack.py b/scripts/dltrack.py
--- a/scripts/dltrack.py
+++ b/scripts/dltrack.py
@@ -235,18 +235,19 @@
# project, smooth and save
for num, obj in objects.items():
features = obj.getFeatures()
- if moving.userTypeNames[obj.getUserType()] == 'pedestrian':
- assert len(features) == 2
- t1 = features[0].getPositions()
- t2 = features[1].getPositions()
- t = [[(p1.x+p2.x)/2., max(p1.y, p2.y)] for p1, p2 in zip(t1, t2)]
- else:
- t = []
- for instant in obj.getTimeInterval():
- points = [f.getPositionAtInstant(instant) for f in features if f.existsAtInstant(instant)]
- t.append(moving.Point.agg(points, np.mean).aslist())
- #t = sum([f.getPositions().asArray() for f in features])/len(features)
- #t = (moving.Trajectory.add(t1, t2)*0.5).asArray()
+ # possible to save bottom pedestrians? not consistent with other users
+ # if moving.userTypeNames[obj.getUserType()] == 'pedestrian':
+ # assert len(features) == 2
+ # t1 = features[0].getPositions()
+ # t2 = features[1].getPositions()
+ # t = [[(p1.x+p2.x)/2., max(p1.y, p2.y)] for p1, p2 in zip(t1, t2)]
+ # else:
+ t = []
+ for instant in obj.getTimeInterval():
+ points = [f.getPositionAtInstant(instant) for f in features if f.existsAtInstant(instant)]
+ t.append(moving.Point.agg(points, np.mean).aslist())
+ #t = sum([f.getPositions().asArray() for f in features])/len(features)
+ #t = (moving.Trajectory.add(t1, t2)*0.5).asArray()
projected = cvutils.imageToWorldProject(np.array(t).T, intrinsicCameraMatrix, distortionCoefficients, homography)
featureNum = features[0].getNum()
obj.features=[moving.MovingObject(featureNum, obj.getTimeInterval(), moving.Trajectory(projected.tolist()))]
diff --git a/trafficintelligence/indicators.py b/trafficintelligence/indicators.py
--- a/trafficintelligence/indicators.py
+++ b/trafficintelligence/indicators.py
@@ -185,12 +185,19 @@
else:
return None
- def getInstantOfMostSevereValue(self):
- '''Returns the instant at which the indicator reaches its most severe value'''
- if self.mostSevereIsMax:
- return max(self.values, key=self.values.get)
+ def getInstantOfMostSevereValue(self, minSevereValue = None):
+ '''Returns the instant at which the indicator reaches its most severe value
+ or the instants when value is above minSevereValue (it not None)'''
+ if minSevereValue is None:
+ if self.mostSevereIsMax:
+ return max(self.values, key=self.values.get)
+ else:
+ return min(self.values, key=self.values.get)
else:
- return min(self.values, key=self.values.get)
+ if self.mostSevereIsMax:
+ return [t for t in self.values if self.values[t] >= minSevereValue]
+ else:
+ return [t for t in self.values if self.values[t] <= minSevereValue]
# functions to aggregate discretized maps of indicators
# TODO add values in the cells between the positions (similar to discretizing vector graphics to bitmap)
diff --git a/trafficintelligence/storage.py b/trafficintelligence/storage.py
--- a/trafficintelligence/storage.py
+++ b/trafficintelligence/storage.py
@@ -497,7 +497,7 @@
cursor.execute('INSERT INTO interactions VALUES({}, {}, {}, {}, {})'.format(interaction.getNum(), roadUserNumbers[0], roadUserNumbers[1], interaction.getFirstInstant(), interaction.getLastInstant()))
def saveInteractionsToSqlite(filename, interactions):
- 'Saves the interactions in the table'
+ 'Saves only the interactions in the table'
with sqlite3.connect(filename) as connection:
cursor = connection.cursor()
try: