Mercurial Hosting > traffic-intelligence
changeset 103:1621b46a1523
started python script to compute the moving object trajectory as the trajectory of the lowest of the features (ie closest to the ground)
author | Nicolas Saunier <nico@confins.net> |
---|---|
date | Wed, 13 Jul 2011 19:14:17 -0400 |
parents | abfc54c097d4 |
children | 13187af8622d |
files | python/compute-object-from-features.py |
diffstat | 1 files changed, 48 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/compute-object-from-features.py Wed Jul 13 19:14:17 2011 -0400 @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +import sys + +import matplotlib.mlab as pylab +import matplotlib.pyplot as plt +import numpy as np + +import cv +import utils +import cvutils +import ubc_utils +import moving + +# use something like getopt to manage arguments if necessary + +if len(sys.argv) < 3: + print('Usage: {0} <video-filename> <n-objects>'.format(sys.argv[0])) + sys.exit() + +if sys.argv[1].endswith('.avi'): + videoFilenamePrefix = utils.removeExtension(sys.argv[1],'.') +else: + videoFilenamePrefix = sys.argv[1] + +objectNum = int(sys.argv[2]) + +objects = ubc_utils.loadTrajectories(videoFilenamePrefix+'-objects.txt', objectNum+1) +obj = objects[objectNum] +features = ubc_utils.loadTrajectories(videoFilenamePrefix+'-features.txt', max(obj.featureNumbers)+1) +h = np.loadtxt(videoFilenamePrefix+'-homography.txt') + +invh = cvutils.invertHomography(h) + +yCoordinates = -np.ones((len(obj.featureNumbers),int(obj.length()))) +for i,fnum in enumerate(obj.featureNumbers): + traj = features[fnum].getPositions().asArray() + imgTraj = cvutils.projectArray(invh, traj) + yCoordinates[i,features[fnum].getFirstInstant()-obj.getFirstInstant():features[fnum].getLastInstant()+1-obj.getFirstInstant()] = imgTraj[1,:] + +indices = argmax(yCoordinates,0) +newTraj = moving.Trajectory() +for j,idx in enumerate(indices): + newTraj.addPosition(features[obj.featureNumbers[idx]].getPositionAtInstant(j+obj.getFirstInstant())) + +# TODO +# use kalman filter over the resulting trajectory +# estimate the error terms using actual features