comparison trafficintelligence/moving.py @ 1240:bb14f919d1cb

cleaned use of centile (np only) and added info in classify-objects
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 05 Feb 2024 14:14:14 -0500
parents d5695e0b59d9
children ab4c72b9475c
comparison
equal deleted inserted replaced
1239:31173c4699d2 1240:bb14f919d1cb
2 '''Libraries for moving objects, trajectories...''' 2 '''Libraries for moving objects, trajectories...'''
3 3
4 import copy 4 import copy
5 from math import sqrt, atan2, cos, sin 5 from math import sqrt, atan2, cos, sin
6 6
7 from numpy import median, mean, array, arange, zeros, ones, hypot, NaN, std, floor, ceil, float32, argwhere, minimum, issubdtype, integer as npinteger 7 from numpy import median, mean, array, arange, zeros, ones, hypot, NaN, std, floor, ceil, float32, argwhere, minimum, issubdtype, integer as npinteger, percentile
8 from matplotlib.pyplot import plot, text, arrow 8 from matplotlib.pyplot import plot, text, arrow
9 from scipy.stats import scoreatpercentile
10 from scipy.spatial.distance import cdist 9 from scipy.spatial.distance import cdist
11 from scipy.signal import savgol_filter 10 from scipy.signal import savgol_filter
12 11
13 try: 12 try:
14 from shapely.geometry import Polygon, Point as shapelyPoint 13 from shapely.geometry import Polygon, Point as shapelyPoint
1848 cvutils.displayTrajectories(videoFilename, [self], homography = homography, firstFrameNum = self.getFirstInstant(), lastFrameNumArg = self.getLastInstant(), undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication) 1847 cvutils.displayTrajectories(videoFilename, [self], homography = homography, firstFrameNum = self.getFirstInstant(), lastFrameNumArg = self.getLastInstant(), undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication)
1849 1848
1850 def speedDiagnostics(self, framerate = 1., display = False, nInstantsIgnoredAtEnds=0): 1849 def speedDiagnostics(self, framerate = 1., display = False, nInstantsIgnoredAtEnds=0):
1851 speeds = framerate*self.getSpeeds(nInstantsIgnoredAtEnds) 1850 speeds = framerate*self.getSpeeds(nInstantsIgnoredAtEnds)
1852 coef = utils.linearRegression(list(range(len(speeds))), speeds) 1851 coef = utils.linearRegression(list(range(len(speeds))), speeds)
1853 print('min/5th perc speed: {} / {}\nspeed diff: {}\nspeed stdev: {}\nregression: {}'.format(min(speeds), scoreatpercentile(speeds, 5), speeds[-2]-speeds[1], std(speeds), coef[0])) 1852 print('min/5th perc speed: {} / {}\nspeed diff: {}\nspeed stdev: {}\nregression: {}'.format(min(speeds), percentile(speeds, 5), speeds[-2]-speeds[1], std(speeds), coef[0]))
1854 if display: 1853 if display:
1855 from matplotlib.pyplot import figure, axis 1854 from matplotlib.pyplot import figure, axis
1856 figure(1) 1855 figure(1)
1857 self.plot() 1856 self.plot()
1858 axis('equal') 1857 axis('equal')