Mercurial Hosting > traffic-intelligence
changeset 13:30559b2cf7a9
minimal code to load UBC data
author | Nicolas Saunier <nico@confins.net> |
---|---|
date | Fri, 13 Nov 2009 19:29:01 -0500 |
parents | ff5403319cec |
children | e7bbe8465591 |
files | c/Makefile python/moving.py python/ubc_utils.py |
diffstat | 3 files changed, 57 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/c/Makefile Wed Nov 11 23:25:23 2009 -0500 +++ b/c/Makefile Fri Nov 13 19:29:01 2009 -0500 @@ -46,7 +46,7 @@ OBJS = $(COMMON_OBJS) $(CV_OBJS) #TESTS_OBJS = -default: all builddir +default: builddir all all: test-pixels optical-flow
--- a/python/moving.py Wed Nov 11 23:25:23 2009 -0500 +++ b/python/moving.py Fri Nov 13 19:29:01 2009 -0500 @@ -114,8 +114,12 @@ self.type = type # compute bounding polygon from trajectory + def draw(self): + self.positions.draw() + # def computeVelocities(self): +# need for a class representing the indicators, their units, how to print them in graphs... class TemporalIndicator: '''Class for temporal indicators i.e. indicators that take a value at specific instants'''
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/ubc_utils.py Fri Nov 13 19:29:01 2009 -0500 @@ -0,0 +1,52 @@ +#! /usr/bin/env python +'''Various utilities to load data saved by the UBC tool(s)''' + +import utils +from moving import MovingObject, TimeInterval, Trajectory + +__metaclass__ = type + +delimiterChar = '%'; + +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 loadTrajectories(filename, nObjects = -1): + '''Loads trajectories''' + + file = utils.openCheck(filename) + if (not file): + return [] + + objects = [] + objNum = 0 + lines = getLines(file) + while (lines != []) and ((nObjects<0) or (objNum<nObjects)): + l = lines[0].split(' ') + parsedLine = [int(n) for n in l[:4]] + obj = MovingObject(num = objNum, timeInterval = TimeInterval(parsedLine[1],parsedLine[2])) + add = True + if (len(lines) >= 3): + obj.positions = Trajectory([[float(n) for n in lines[1].split(' ')], + [float(n) for n in lines[2].split(' ')]]) + if (len(lines) >= 5): + obj.velocity = Trajectory([[float(n) for n in lines[3].split(' ')], + [float(n) for n in lines[4].split(' ')]]) + + if len(lines) != 2: + objects.append(obj) + objNum+=1 + else: + print("Error two lines of data for feature %d"%(f.num)) + + lines = getLines(file) + + file.close() + return objects +