diff python/cvutils.py @ 402:f29204e68aab

function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 29 Jul 2013 19:45:43 -0400
parents 3399bd48cb40
children 37c7b46f6e21
line wrap: on
line diff
--- a/python/cvutils.py	Mon Jul 29 18:58:05 2013 -0400
+++ b/python/cvutils.py	Mon Jul 29 19:45:43 2013 -0400
@@ -79,7 +79,7 @@
     return a
 
 if opencvAvailable:
-    def computeHomography(srcPoints, dstPoints, method=0, ransacReprojThreshold=0.0):
+    def computeHomography(srcPoints, dstPoints, method=0, ransacReprojThreshold=3.0):
         '''Returns the homography matrix mapping from srcPoints to dstPoints (dimension Nx2)'''
         H, mask = cv2.findHomography(srcPoints, dstPoints, method, ransacReprojThreshold)
         return H
@@ -162,7 +162,6 @@
         else:
             print('Video capture failed')
         return images
-
     
     def getFPS(videoFilename):
         capture = cv2.VideoCapture(videoFilename)
@@ -210,6 +209,21 @@
                         cv2.imwrite('image.png', img)
                     frameNum += 1
             cv2.destroyAllWindows()
+
+    def computeHomographyFromPDTV(cameraFilename, method=0, ransacReprojThreshold=3.0):
+        '''Returns the homography matrix at ground level from PDTV format
+        https://bitbucket.org/hakanardo/pdtv'''
+        import pdtv
+        from numpy import array
+        camera = pdtv.load(cameraFilename)
+        srcPoints = [[x,y] for x, y in zip([1.,2.,2.,1.],[1.,1.,2.,2.])] # need floats!!
+        dstPoints = []
+        for srcPoint in srcPoints:
+            projected = camera.image_to_world(tuple(srcPoint))
+            dstPoints.append([projected[0], projected[1]])
+        H, mask = cv2.findHomography(array(srcPoints), array(dstPoints), method, ransacReprojThreshold)
+        return H
+
     
 def printCvMat(cvmat, out = stdout):
     '''Prints the cvmat to out'''