Mercurial Hosting > traffic-intelligence
diff python/utils.py @ 48:8aed225f71d8
rearranged code for function readline and getlines (and characters), moved invertHomography to cvutils
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 23 Sep 2010 17:24:31 -0400 |
parents | b5d007612e16 |
children | 75cf537b8d88 |
line wrap: on
line diff
--- a/python/utils.py Thu Sep 23 17:12:09 2010 -0400 +++ b/python/utils.py Thu Sep 23 17:24:31 2010 -0400 @@ -10,6 +10,8 @@ commentChar = '#' +delimiterChar = '%'; + ######################### # simple statistics ######################### @@ -146,13 +148,22 @@ exit() return None -def readline(f): +def readline(f, commentCharacter = commentChar): '''Modified readline function to skip comments.''' s = f.readline() - while (len(s) > 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