Mercurial Hosting > traffic-intelligence
changeset 28:9ae709a2e8d0
rearranged code
author | Nicolas Saunier <nico@confins.net> |
---|---|
date | Sat, 30 Jan 2010 21:42:53 -0500 |
parents | 44689029a86f |
children | ca8e716cc231 |
files | python/cvutils.py python/moving.py |
diffstat | 2 files changed, 56 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/cvutils.py Sat Jan 30 21:42:53 2010 -0500 @@ -0,0 +1,53 @@ +#! /usr/bin/env python +'''Image/Video utilities''' + +import Image, ImageDraw # PIL +import aggdraw # agg on top of PIL (antialiased drawing) +from moving import Point +#import utils + +__metaclass__ = type + +def drawLines(filename, origins, destinations, w = 1, resultFilename='image.png'): + '''Draws lines over the image ''' + + img = Image.open(filename) + + draw = ImageDraw.Draw(img) + #draw = aggdraw.Draw(img) + #pen = aggdraw.Pen("red", width) + for p1, p2 in zip(origins, destinations): + draw.line([p1.x, p1.y, p2.x, p2.y], width = w, fill = (256,0,0)) + #draw.line([p1.x, p1.y, p2.x, p2.y], pen) + del draw + + #out = utils.openCheck(resultFilename) + img.save(resultFilename) + +def project(homography, p): + '''Returns the coordinates of the projection of the point p + through homography''' + from numpy.core._dotblas import dot + from numpy.core.multiarray import array + from numpy.lib.function_base import insert + if (homography!=None) and (len(homography)>0): + pAugmented = insert(array(p.aslist()), [2],[1], axis=0) + tmp = dot(homography, pAugmented) + return Point(tmp[0]/tmp[2], tmp[1]/tmp[2]) + else: + return p + +def projectTrajectory(homography, trajectory): + '''Projects a series of points in the format + [[x1, x2, ...], + [y1, y2, ...]] + + Warning: not optimized, calls project()''' + projected = [[],[]] + for x, y in zip(trajectory[0], trajectory[1]): + p = [x,y] + pp = project(homography, p) + projected[0].append(pp[0]) + projected[1].append(pp[1]) + return projected +
--- a/python/moving.py Sat Dec 05 15:40:28 2009 -0500 +++ b/python/moving.py Sat Jan 30 21:42:53 2010 -0500 @@ -141,6 +141,9 @@ ''' return Point(self.x-other.x, self.y-other.y) + def aslist(self): + return [self.x, self.y] + class Trajectory: '''Class for trajectories i.e. a temporal sequence of positions