changeset 236:eb4525853030

added script to display trajectories
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 06 Jul 2012 01:03:52 -0400
parents 584613399513
children 6774bdce03f1
files python/compute-homography.py python/cvutils.py python/display-trajectories.py
diffstat 3 files changed, 37 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/python/compute-homography.py	Thu Jul 05 23:32:14 2012 -0400
+++ b/python/compute-homography.py	Fri Jul 06 01:03:52 2012 -0400
@@ -57,7 +57,9 @@
     print('''The positional argument should be the name
  of a file containing at least 4 non-colinear point coordinates (point correspondences:
  - the first two lines are the x and y coordinates in the projected space (usually world space)
- - the last two lines are the x and y coordinates in the origin space (usually image space)''')
+ - the last two lines are the x and y coordinates in the origin space (usually image space)
+
+if providing a video frame, the image points and back projected world points will be plotted''')
     sys.exit()
 
 dstPts, srcPts = cvutils.loadPointCorrespondences(args[0])
--- a/python/cvutils.py	Thu Jul 05 23:32:14 2012 -0400
+++ b/python/cvutils.py	Fri Jul 06 01:03:52 2012 -0400
@@ -143,7 +143,7 @@
                     print('frame {0}'.format(frameNum))
                     for obj in objects:
                         if obj.existsAtInstant(frameNum):
-                            if obj.getFirstInstant() == frameNum:
+                            if not hasattr(obj, 'projectedPositions'):
                                 if homography != None:
                                     obj.projectedPositions = obj.positions.project(homography)
                                 else:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/display-trajectories.py	Fri Jul 06 01:03:52 2012 -0400
@@ -0,0 +1,33 @@
+#! /usr/bin/env python
+
+import sys,getopt
+
+import storage
+import cvutils
+
+from numpy.linalg.linalg import inv
+from numpy.lib.npyio import loadtxt
+
+options, args = getopt.getopt(sys.argv[1:], 'hi:d:t:o:f:',['help']) 
+# alternative long names are a pain to support ,'video-filename=','database-filename=', 'type='
+# todo parse the cfg file (problem, python ConfigParser needs section headers)
+options = dict(options)
+
+if '--help' in options.keys() or '-h' in options.keys() or len(sys.argv) == 1 or not '-i' in options.keys() or not '-d' in options.keys():
+    print('Usage: {0} --help|-h -i video-filename -d database-filename [-t object_type] [-o image2world_homography] [-f first_frame]'.format(sys.argv[0]))
+    sys.exit()
+
+objectType = 'feature'
+if '-t' in options.keys():
+    objectType = options['-t']
+
+objects = storage.loadTrajectoriesFromSqlite(options['-d'], objectType)
+
+homography = None
+if '-o' in options.keys():
+    homography = inv(loadtxt(options['-o']))
+firstFrameNum = 0
+if '-f' in options.keys():
+    firstFrameNum = int(options['-f'])
+
+cvutils.displayTrajectories(options['-i'], objects, homography, firstFrameNum)