Mercurial Hosting > traffic-intelligence
changeset 29:ca8e716cc231
added moving average filter
author | Nicolas Saunier <nico@confins.net> |
---|---|
date | Sat, 30 Jan 2010 21:43:07 -0500 |
parents | 9ae709a2e8d0 |
children | 418b41056e6c |
files | python/utils.py |
diffstat | 1 files changed, 10 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/python/utils.py Sat Jan 30 21:42:53 2010 -0500 +++ b/python/utils.py Sat Jan 30 21:43:07 2010 -0500 @@ -49,6 +49,16 @@ def crossProduct(l1, l2): return l1[0]*l2[1]-l1[1]*l2[0] +def filterMovingWindow(input, halfWidth): + '''Returns an array obtained after the smoothing of the input by a moving average + The first and last points are copied from the original.''' + width = float(halfWidth*2+1) + win = ones(width,'d') + result = convolve(win/width,array(inputSignal),'same') + result[:halfWidth] = inputSignal[:halfWidth] + result[-halfWidth:] = inputSignal[-halfWidth:] + return result + ######################### # file I/O section ######################### @@ -113,35 +123,6 @@ invH /= invH[2,2] return invH -def project(homography, p): - '''Returns the coordinates of the projection of the point p - through homography''' - from numpy.core._dotblas import dot - from numpy.core.multiarray import array - from numpy.lib.function_base import insert - if (homography!=None) and (len(homography)>0): - pAugmented = insert(array(p), [2],[1], axis=0) - projected = dot(homography, pAugmented) - projected[0] /= projected[2] - projected[1] /= projected[2] - else: - projected = p - return projected[:2] - -def projectTrajectory(homography, trajectory): - '''Projects a series of points in the format - [[x1, x2, ...], - [y1, y2, ...]] - - Warning: not optimized, calls project()''' - projected = [[],[]] - for x, y in zip(trajectory[0], trajectory[1]): - p = [x,y] - pp = project(homography, p) - projected[0].append(pp[0]) - projected[1].append(pp[1]) - return projected - def plotPolygon(poly, options = ''): from numpy.core.multiarray import array from matplotlib.pyplot import plot