changeset 159:115f7f90286d

updated calibration-translation and added function to convert point correspondences
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 12 Sep 2011 16:38:47 -0400
parents 2d7c6d767a39
children b0719b3ad3db
files python/calibration-translation.py python/cvutils.py
diffstat 2 files changed, 29 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/python/calibration-translation.py	Fri Sep 09 19:23:11 2011 -0400
+++ b/python/calibration-translation.py	Mon Sep 12 16:38:47 2011 -0400
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 
 import sys
+import os
 
 import matplotlib.mlab as pylab
 import matplotlib.pyplot as plt
@@ -33,8 +34,8 @@
 
 #referenceHomography = np.loadtxt(referenceHomographyFilename)
 referenceVideoIndex = filenames.index(referenceVideoFilename)
-indices = set([1, 2, 3, 4, 5, 6, 7, 9, 10, 11])#set(range(len(filenames)))
-#indices.discard(referenceVideoIndex)
+indices = set(range(len(filenames)))
+indices.discard(referenceVideoIndex)
 
 images = {}
 #features = {}
@@ -58,26 +59,28 @@
 
 for f in filenames: # get suitable image references for each video
     captures[f] = cv2.VideoCapture(f)
-    # TODO if frame image already exists, no need to search for it again
-    key = -1
-    while key != cvutils.cvKeyNumbers['y']:
-        (ret, img) = captures[f].read()
-        cv2.imshow('Image',img)
-        print('Can one see the reference points in the image? (y/n)')
-        key = cv2.waitKey(0)
+    frameFilename = utils.removeExtension(f)+'-frame.png' # TODO if frame image already exists, no need to search for it again
+    if not os.path.exists(frameFilename):
+        key = -1
+        while key != cvutils.cvKeyNumbers['y']:
+            (ret, img) = captures[f].read()
+            cv2.imshow('Image',img)
+            print('Can one see the reference points in the image? (y/n)')
+            key = cv2.waitKey(0)
 
-    images[f] = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
-    cv2.imwrite(utils.removeExtension(f)+'-frame.png', img)
-    #images[f] = cv2.imread(f, cv2.CV_LOAD_IMAGE_GRAYSCALE)
+        images[f] = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
+        cv2.imwrite(frameFilename, img)
+    else:
+        images[f] = cv2.imread(frameFilename, cv2.CV_LOAD_IMAGE_GRAYSCALE)
     #features[f] = cv2.goodFeaturesToTrack(images[f], 1000, 0.02, 2, useHarrisDetector = True, mask=maskImg) # todo put parameters on the command line ? 
     # goodFeaturesToTrack(image, maxCorners, qualityLevel, minDistance[, corners[, mask[, blockSize[, useHarrisDetector[, k]]]]])
     # display features
-    if False:
-        display = img.copy()#cv2.cvtColor(images[f], cv2.COLOR_GRAY2RGB) #.copy()
-        for p in features[f]:
-            cv2.circle(display, tuple(p[0]), 3, (255,0,0))
-        cv2.imshow('Reference',display)
-        cv2.waitKey()
+    # if False:
+    #     display = img.copy()#cv2.cvtColor(images[f], cv2.COLOR_GRAY2RGB) #.copy()
+    #     for p in features[f]:
+    #         cv2.circle(display, tuple(p[0]), 3, (255,0,0))
+    #     cv2.imshow('Reference',display)
+    #     cv2.waitKey()
 
 plt.close('all')
 
--- a/python/cvutils.py	Fri Sep 09 19:23:11 2011 -0400
+++ b/python/cvutils.py	Mon Sep 12 16:38:47 2011 -0400
@@ -44,6 +44,14 @@
     #out = utils.openCheck(resultFilename)
     img.save(resultFilename)
 
+def matlab2PointCorrespondences(filename):
+    '''Loads and converts the point correspondences saved 
+    by the matlab camera calibration tool'''
+    from numpy.lib.io import loadtxt, savetxt
+    from numpy.lib.function_base import append
+    points = loadtxt(filename, delimiter=',')
+    savetxt(utils.removeExtension(filename)+'-point-correspondences.txt',append(points[:,:2].T, points[:,3:].T, axis=0))
+
 def computeHomography(srcPoints, dstPoints, method=0, ransacReprojThreshold=0.0):
     '''Returns the homography matrix mapping from srcPoints to dstPoints (dimension Nx2)'''
     #cvSrcPoints = arrayToCvMat(srcPoints);