Mercurial Hosting > traffic-intelligence
changeset 44:be3ae926e4e8
added simple intersection description, function to load collision points
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sat, 31 Jul 2010 23:39:17 -0400 |
parents | 6d11d9e7ad4e |
children | 74d2de078baf |
files | python/cvutils.py python/ubc_utils.py |
diffstat | 2 files changed, 42 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/python/cvutils.py Wed Jul 14 14:02:11 2010 -0400 +++ b/python/cvutils.py Sat Jul 31 23:39:17 2010 -0400 @@ -2,7 +2,7 @@ '''Image/Video utilities''' import Image, ImageDraw # PIL -import aggdraw # agg on top of PIL (antialiased drawing) +#import aggdraw # agg on top of PIL (antialiased drawing) from moving import Point #import utils @@ -51,3 +51,23 @@ projected[1].append(pp[1]) return projected +class WorldSpaceData: + '''Simple class for simple intersection outline''' + def __init__(self, dimension, coordX, coordY): + self.dimension = dimension + self.coordX = coordX + self.coordY = coordY + + def plot(self, options = 'k'): + from matplotlib.pyplot import plot, axis + + minX = min(self.dimension[0]) + maxX = max(self.dimension[0]) + minY = min(self.dimension[1]) + maxY = max(self.dimension[1]) + + plot([minX, self.coordX[0], self.coordX[0]], [self.coordY[0], self.coordY[0], minY],options) + plot([self.coordX[1], self.coordX[1], maxX], [minY, self.coordY[0], self.coordY[0]],options) + plot([minX, self.coordX[0], self.coordX[0]], [self.coordY[1], self.coordY[1], maxY],options) + plot([self.coordX[1], self.coordX[1], maxX], [maxY, self.coordY[1], self.coordY[1]],options) + axis('equal')
--- a/python/ubc_utils.py Wed Jul 14 14:02:11 2010 -0400 +++ b/python/ubc_utils.py Sat Jul 31 23:39:17 2010 -0400 @@ -59,3 +59,24 @@ file.close() return objects +def loadCollisionPoints(filename, nPoints = -1): + '''Loads collision points and returns a dict + with keys as a pair of the numbers of the two interacting objects''' + file = utils.openCheck(filename) + if (not file): + return [] + + points = {} + num = 0 + lines = getLines(file) + while (lines != []) and ((nPoints<0) or (num<nPoints)): + parsedLine = [int(n) for n in lines[0].split(' ')] + protagonistNums = (parsedLine[0], parsedLine[1]) + points[protagonistNums] = [[float(n) for n in lines[1].split(' ')], + [float(n) for n in lines[2].split(' ')]] + + num+=1 + lines = getLines(file) + + file.close() + return points