nsaunier/traffic-intelligence
added moving average smoothing for kitti loading
Commit 785c86013d2c · Nicolas Saunier · 2024-06-17 22:49 -0400
Comments
No comments yet.
Diff
diff --git a/trafficintelligence/pavement.py b/trafficintelligence/pavement.py
--- a/trafficintelligence/pavement.py
+++ b/trafficintelligence/pavement.py
@@ -35,10 +35,10 @@
def caracteristiques(rtss, maintenanceLevel, rtssWeatherStation, fmr, paintType):
'''Computes characteristic data for the RTSS (class rtss)
- maintenanceLevel = pylab.csv2rec('C:\\Users\Alexandre\Desktop\Projet_maitrise_recherche\BDD_access\\analyse_donnees_deneigement\\exigence_circuits.txt', delimiter = ';')
- rtssWeatherStation = pylab.csv2rec('C:\\Users\Alexandre\Desktop\Projet_maitrise_recherche\stations_environnement_canada\\rtssWeatherStation\juste_pour_rtss_avec_donnees_entretien_hiv\\rtssWeatherStation_EC3.txt', delimiter = ',')
- fmr = pylab.csv2rec('C:\\Users\Alexandre\Desktop\Projet_maitrise_recherche\BDD_access\\analyse_donnees_deneigement\\fmr.txt', delimiter = ';')
- paintType = pylab.csv2rec('C:\\Users\Alexandre\Desktop\Projet_maitrise_recherche\BDD_access\\analyse_donnees_deneigement\\type_peinture.txt', delimiter = ';')
+ maintenanceLevel = pylab.csv2rec('C:\\Users\\Alexandre\\Desktop\\Projet_maitrise_recherche\\BDD_access\\analyse_donnees_deneigement\\exigence_circuits.txt', delimiter = ';')
+ rtssWeatherStation = pylab.csv2rec('C:\\Users\\Alexandre\\Desktop\\Projet_maitrise_recherche\\stations_environnement_canada\\rtssWeatherStation\\juste_pour_rtss_avec_donnees_entretien_hiv\\rtssWeatherStation_EC3.txt', delimiter = ',')
+ fmr = pylab.csv2rec('C:\\Users\\Alexandre\\Desktop\\Projet_maitrise_recherche\\BDD_access\\analyse_donnees_deneigement\\fmr.txt', delimiter = ';')
+ paintType = pylab.csv2rec('C:\\Users\\Alexandre\\Desktop\\Projet_maitrise_recherche\\BDD_access\\analyse_donnees_deneigement\\type_peinture.txt', delimiter = ';')
'''
# determination exigence deneigement
if rtss.id in maintenanceLevel['rtss_debut']:
@@ -104,7 +104,7 @@
def winterMaintenanceIndicators(data, startDate, endDate, circuitReference, snowThreshold):
'''Computes several winter maintenance indicators
- data = entretien_hivernal = pylab.csv2rec('C:\\Users\Alexandre\Documents\Cours\Poly\Projet\mesures_entretien_hivernal\mesures_deneigement.txt', delimiter = ',')'''
+ data = entretien_hivernal = pylab.csv2rec('C:\\Users\\Alexandre\\Documents\\Cours\\Poly\\Projet\\mesures_entretien_hivernal\\mesures_deneigement.txt', delimiter = ',')'''
somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, compteur_premiere_neige, compteur_somme_abrasif = 0,0,0,0,0,0,0,0,0
if circuitReference in data['ref_circuit']:
diff --git a/trafficintelligence/storage.py b/trafficintelligence/storage.py
--- a/trafficintelligence/storage.py
+++ b/trafficintelligence/storage.py
@@ -1312,13 +1312,14 @@
# from https://github.com/utiasSTARS/pykitti/blob/master/pykitti/utils.py
-def loadTrajectoriesFromKITTI(filename, kittiCalibration = None, oxts = None, resultFile = False):
+def loadTrajectoriesFromKITTI(filename, kittiCalibration = None, oxts = None, resultFile = False, halfWidth = None):
'''Reads data from KITTI ground truth or output from an object detection and tracking method
kittiCalibration is obtained from loading training/testing calibration file for each sequence 00XX.txt
oxts is obtained using utils.load_oxts_packets_and_poses(['./training/oxts/0001.txt']) from pykitti
+ Ref: https://github.com/pratikac/kitti/blob/master/readme.tracking.txt
- Ref: https://github.com/pratikac/kitti/blob/master/readme.tracking.txt'''
+ non-null halfWidth indicates positions are smoothed using moving window avefraging'''
from pykitti.utils import roty, rotz
from trafficintelligence.cvutils import cartesian2Homogeneous
@@ -1431,6 +1432,9 @@
featureTrajectories[j].addPositionXY(xCoords[j], yCoords[j])
# check https://docs.opencv.org/3.4/d9/d0c/group__calib3d.html#ga1019495a2c8d1743ed5cc23fa0daff8c
if interval.length()>1:
+ if halfWidth is not None:
+ for i in range(4):
+ featureTrajectories[i] = featureTrajectories[i].filterMovingWindow(halfWidth)
objects.append(moving.MovingObject(num = objNum, timeInterval = interval, positions = t, velocities = t.differentiate(True), userType = userType, features = [moving.MovingObject(num = featureNum+i, timeInterval = copy(interval), positions = featureTrajectories[i], velocities = featureTrajectories[i].differentiate(True)) for i in range(4)]))
featureNum += 4
@@ -1470,17 +1474,22 @@
for i in range(4):
featureTrajectories[i].addPositionXY(xCoords[i], yCoords[i])
# check https://docs.opencv.org/3.4/d9/d0c/group__calib3d.html#ga1019495a2c8d1743ed5cc23fa0daff8c
+ if halfWidth is not None:
+ for i in range(4):
+ featureTrajectories[i] = featureTrajectories[i].filterMovingWindow(halfWidth)
objects.append(moving.MovingObject(num = max([o.getNum() for o in objects])+1, timeInterval = interval, positions = t, velocities = t.differentiate(True), userType = 'Car', features = [moving.MovingObject(num = featureNum+i, timeInterval = copy(interval), positions = featureTrajectories[i], velocities = featureTrajectories[i].differentiate(True)) for i in range(4)]))
return objects
-def loadTrajectoriesFromKITTI2D(filename, kittiCalibration = None, oxts = None):
+def loadTrajectoriesFromKITTI2D(filename, kittiCalibration = None, oxts = None, halfWidth = None):
'''Loads x,y coordinate series
e.g. obtained by projecting from image to ground world plane using a homography
Format: frame_id,track_id,usertype,x,y,score
if oxts is not None, it is obtained using utils.load_oxts_packets_and_poses(['./training/oxts/0001.txt']) from pykitti
- to generate the movement of the ego vehicle'''
+ to generate the movement of the ego vehicle
+
+ non-null halfWidth indicates positions are smoothed using moving window avefraging'''
header = ['frame','trackingid','usertype','x','y','score']
data = read_csv(filename, delimiter=' ', names = header)
@@ -1497,6 +1506,8 @@
#print(tmp.info())
if interval.length()>1:
t = moving.Trajectory([tmp.x.to_list(), tmp.y.to_list()])
+ if halfWidth is not None:
+ t = t.filterMovingWindow(halfWidth)
objects.append(moving.MovingObject(num = objNum, timeInterval = interval, positions = t, velocities = t.differentiate(True), userType = userType))
# ego vehicle
@@ -1526,6 +1537,8 @@
xCoords = worldCorners[:4,0]
yCoords = worldCorners[:4,1]
t.addPositionXY(xCoords.mean(), yCoords.mean())
+ if halfWidth is not None:
+ t = t.filterMovingWindow(halfWidth)
objects.append(moving.MovingObject(num = max([o.getNum() for o in objects])+1, timeInterval = interval, positions = t, velocities = t.differentiate(True), userType = 'Car'))
return objects