diff python/cvutils.py @ 302:9d88a4d97473

corrected bug in compute-homography
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 18 Mar 2013 23:37:45 -0400
parents aba9711b3149
children 514f6b98cd8c
line wrap: on
line diff
--- 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)