# HG changeset patch # User Nicolas Saunier # Date 1285277071 14400 # Node ID 8aed225f71d8327868d8139a61ad8959eb83a129 # Parent e27598865af3cadfe41d29794e98b8ea0a667868 rearranged code for function readline and getlines (and characters), moved invertHomography to cvutils diff -r e27598865af3 -r 8aed225f71d8 python/cvutils.py --- a/python/cvutils.py Thu Sep 23 17:12:09 2010 -0400 +++ b/python/cvutils.py Thu Sep 23 17:24:31 2010 -0400 @@ -51,6 +51,13 @@ projected[1].append(pp[1]) return projected +def invertHomography(homography): + 'Returns an inverted homography' + from numpy.linalg.linalg import inv + invH = inv(homography) + invH /= invH[2,2] + return invH + class WorldSpaceData: '''Simple class for simple intersection outline''' def __init__(self, dimension, coordX, coordY): diff -r e27598865af3 -r 8aed225f71d8 python/storage.py --- a/python/storage.py Thu Sep 23 17:12:09 2010 -0400 +++ b/python/storage.py Thu Sep 23 17:24:31 2010 -0400 @@ -85,16 +85,6 @@ out.close() -# other functions -def getLines(f): - '''Gets a complete entry (all the lines) in between delimiterChar.''' - dataStrings = [] - s = utils.myreadline(f) - while (len(s) > 0) and (not s.startswith(delimiterChar)): - dataStrings += [s.strip()] - s = utils.myreadline(f) - return dataStrings - diff -r e27598865af3 -r 8aed225f71d8 python/ubc_utils.py --- a/python/ubc_utils.py Thu Sep 23 17:12:09 2010 -0400 +++ b/python/ubc_utils.py Thu Sep 23 17:24:31 2010 -0400 @@ -6,8 +6,6 @@ __metaclass__ = type -delimiterChar = '%'; - def getFileType(s): filePrefix = utils.removeExtension(s) i = filePrefix.rfind('-') @@ -16,16 +14,7 @@ else: return '' -def getLines(f): - '''Gets a complete entry (all the lines) in between delimiterChar.''' - dataStrings = [] - s = utils.readline(f) - while (len(s) > 0) and (not s.startswith(delimiterChar)): - dataStrings += [s.strip()] - s = utils.readline(f) - return dataStrings - -def saveTrajectorieUserTypes(inFilename, outFilename, objects): +def saveTrajectoryUserTypes(inFilename, outFilename, objects): '''The program saves the objects, by just copying the corresponding trajectory and velocity data from the inFilename, and saving the characteristics in objects (first line) @@ -36,7 +25,7 @@ if (not infile) | (not outfile): return - lines = getLines(file) + lines = utils.getLines(infile) objNum = 0 while lines != []: i = 0 @@ -47,6 +36,7 @@ outfile.write() # next object objNum += 1 + lines = utils.getLines(infile) def loadTrajectories(filename, nObjects = -1): '''Loads trajectories''' @@ -58,7 +48,7 @@ objects = [] objNum = 0 objectType = getFileType(filename) - lines = getLines(file) + lines = utils.getLines(file) while (lines != []) and ((nObjects<0) or (objNum 0) and s.startswith(commentChar): + while (len(s) > 0) and s.startswith(commentCharacter): s = f.readline() return s.strip() +def getLines(f, delimiterCharacter = delimiterChar): + '''Gets a complete entry (all the lines) in between delimiterChar.''' + dataStrings = [] + s = readline(f) + while (len(s) > 0) and (not s.startswith(delimiterCharacter)): + dataStrings += [s.strip()] + s = readline(f) + return dataStrings + def removeExtension(filename, delimiter = '.'): '''Returns the filename minus the extension (all characters after last .)''' i = filename.rfind(delimiter) @@ -182,13 +193,6 @@ if (os.path.exists(filename)): os.remove(filename) -def invertHomography(homography): - 'Returns an inverted homography' - from numpy.linalg.linalg import inv - invH = inv(homography) - invH /= invH[2,2] - return invH - def plotPolygon(poly, options = ''): from numpy.core.multiarray import array from matplotlib.pyplot import plot