# HG changeset patch # User Nicolas Saunier # Date 1264905787 18000 # Node ID ca8e716cc231b6d9ed09b7b5e68270113df9a5f2 # Parent 9ae709a2e8d044a68606061d4bf2feceaa907047 added moving average filter diff -r 9ae709a2e8d0 -r ca8e716cc231 python/utils.py --- 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