Mercurial > hg > nsaunier > traffic-intelligence
comparison python/compute-object-from-features.py @ 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 | |
| children | 9844c69d8fa2 |
comparison
equal
deleted
inserted
replaced
| 102:abfc54c097d4 | 103:1621b46a1523 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 import sys | |
| 4 | |
| 5 import matplotlib.mlab as pylab | |
| 6 import matplotlib.pyplot as plt | |
| 7 import numpy as np | |
| 8 | |
| 9 import cv | |
| 10 import utils | |
| 11 import cvutils | |
| 12 import ubc_utils | |
| 13 import moving | |
| 14 | |
| 15 # use something like getopt to manage arguments if necessary | |
| 16 | |
| 17 if len(sys.argv) < 3: | |
| 18 print('Usage: {0} <video-filename> <n-objects>'.format(sys.argv[0])) | |
| 19 sys.exit() | |
| 20 | |
| 21 if sys.argv[1].endswith('.avi'): | |
| 22 videoFilenamePrefix = utils.removeExtension(sys.argv[1],'.') | |
| 23 else: | |
| 24 videoFilenamePrefix = sys.argv[1] | |
| 25 | |
| 26 objectNum = int(sys.argv[2]) | |
| 27 | |
| 28 objects = ubc_utils.loadTrajectories(videoFilenamePrefix+'-objects.txt', objectNum+1) | |
| 29 obj = objects[objectNum] | |
| 30 features = ubc_utils.loadTrajectories(videoFilenamePrefix+'-features.txt', max(obj.featureNumbers)+1) | |
| 31 h = np.loadtxt(videoFilenamePrefix+'-homography.txt') | |
| 32 | |
| 33 invh = cvutils.invertHomography(h) | |
| 34 | |
| 35 yCoordinates = -np.ones((len(obj.featureNumbers),int(obj.length()))) | |
| 36 for i,fnum in enumerate(obj.featureNumbers): | |
| 37 traj = features[fnum].getPositions().asArray() | |
| 38 imgTraj = cvutils.projectArray(invh, traj) | |
| 39 yCoordinates[i,features[fnum].getFirstInstant()-obj.getFirstInstant():features[fnum].getLastInstant()+1-obj.getFirstInstant()] = imgTraj[1,:] | |
| 40 | |
| 41 indices = argmax(yCoordinates,0) | |
| 42 newTraj = moving.Trajectory() | |
| 43 for j,idx in enumerate(indices): | |
| 44 newTraj.addPosition(features[obj.featureNumbers[idx]].getPositionAtInstant(j+obj.getFirstInstant())) | |
| 45 | |
| 46 # TODO | |
| 47 # use kalman filter over the resulting trajectory | |
| 48 # estimate the error terms using actual features |
