Mercurial Hosting > traffic-intelligence
changeset 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 | e27598865af3 |
children | 1fb5606506ae |
files | python/cvutils.py python/storage.py python/ubc_utils.py python/utils.py |
diffstat | 4 files changed, 27 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- 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):
--- 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 -
--- 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<nObjects)): l = lines[0].split(' ') parsedLine = [int(n) for n in l[:4]] @@ -88,7 +78,7 @@ else: print("Error two lines of data for feature %d"%(f.num)) - lines = getLines(file) + lines = utils.getLines(file) file.close() return objects @@ -102,7 +92,7 @@ points = {} num = 0 - lines = getLines(file) + lines = utils.getLines(file) while (lines != []) and ((nPoints<0) or (num<nPoints)): parsedLine = [int(n) for n in lines[0].split(' ')] protagonistNums = (parsedLine[0], parsedLine[1]) @@ -110,7 +100,7 @@ [float(n) for n in lines[2].split(' ')]] num+=1 - lines = getLines(file) + lines = utils.getLines(file) file.close() return points
--- 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