changeset 302:9d88a4d97473

corrected bug in compute-homography
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 18 Mar 2013 23:37:45 -0400
parents 27f06d28036d
children 514f6b98cd8c
files python/compute-homography.py python/cvutils.py python/traffic_engineering.py
diffstat 3 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/python/compute-homography.py	Mon Mar 11 01:07:08 2013 -0400
+++ b/python/compute-homography.py	Mon Mar 18 23:37:45 2013 -0400
@@ -71,7 +71,7 @@
 
 homography = np.array([])
 if '-p' in options.keys():
-    worldPts, videoPts = cvutils.loadPointCorrespondences(args[0])
+    worldPts, videoPts = cvutils.loadPointCorrespondences(options['-p'])
     homography, mask = cv2.findHomography(videoPts, worldPts) # method=0, ransacReprojThreshold=3
 elif '-i' in options.keys() and '-w' in options.keys():
     nPoints = 4
--- a/python/cvutils.py	Mon Mar 11 01:07:08 2013 -0400
+++ b/python/cvutils.py	Mon Mar 18 23:37:45 2013 -0400
@@ -59,14 +59,6 @@
     points = loadtxt(filename, dtype=float32)
     return  (points[:2,:].T, points[2:,:].T) # (world points, image points)
 
-def computeHomography(srcPoints, dstPoints, method=0, ransacReprojThreshold=0.0):
-    '''Returns the homography matrix mapping from srcPoints to dstPoints (dimension Nx2)'''
-    #cvSrcPoints = arrayToCvMat(srcPoints);
-    #cvDstPoints = arrayToCvMat(dstPoints);
-    #H = cv.CreateMat(3, 3, cv.CV_64FC1)
-    H, mask = cv2.findHomography(srcPoints, dstPoints, method, ransacReprojThreshold)
-    return H
-
 def cvMatToArray(cvmat):
     '''Converts an OpenCV CvMat to numpy array.'''
     from numpy.core.multiarray import zeros
@@ -77,6 +69,11 @@
     return a
 
 if opencvExists:
+    def computeHomography(srcPoints, dstPoints, method=0, ransacReprojThreshold=0.0):
+        '''Returns the homography matrix mapping from srcPoints to dstPoints (dimension Nx2)'''
+        H, mask = cv2.findHomography(srcPoints, dstPoints, method, ransacReprojThreshold)
+        return H
+
     def arrayToCvMat(a, t = cv2.cv.CV_64FC1):
         '''Converts a numpy array to an OpenCV CvMat, with default type CV_64FC1.'''
         cvmat = cv2.cv.CreateMat(a.shape[0], a.shape[1], t)
--- a/python/traffic_engineering.py	Mon Mar 11 01:07:08 2013 -0400
+++ b/python/traffic_engineering.py	Mon Mar 18 23:37:45 2013 -0400
@@ -3,6 +3,8 @@
 
 from math import ceil
 
+import prediction
+
 __metaclass__ = type
 
 
@@ -11,8 +13,8 @@
 #########################
 
 class Vehicle:
-    'Generic vehicle class
-    1D coordinates for now'
+    '''Generic vehicle class
+    1D coordinates for now'''
     class PredictedTrajectory1D(prediction.PredictedTrajectory):
         def __init__(self, initialPosition, initialSpeed, control, maxSpeed = None):
             self.control = control
@@ -159,6 +161,7 @@
             self.equivalents = equivalents
             self.nLanes = nLanes # unused
         else:
+            print('Proportions do not sum to 1')
             pass
 
     def getPCUVolume(self):