comparison python/cvutils.py @ 384:6da9cf5609aa

adding deprecated messages if old cvmat format
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 22 Jul 2013 18:11:01 -0400
parents 387cc0142211
children 1917db662aa7
comparison
equal deleted inserted replaced
383:0ce2210790b1 384:6da9cf5609aa
68 points = loadtxt(filename, dtype=float32) 68 points = loadtxt(filename, dtype=float32)
69 return (points[:2,:].T, points[2:,:].T) # (world points, image points) 69 return (points[:2,:].T, points[2:,:].T) # (world points, image points)
70 70
71 def cvMatToArray(cvmat): 71 def cvMatToArray(cvmat):
72 '''Converts an OpenCV CvMat to numpy array.''' 72 '''Converts an OpenCV CvMat to numpy array.'''
73 print('Deprecated, use new interface')
73 from numpy.core.multiarray import zeros 74 from numpy.core.multiarray import zeros
74 a = zeros((cvmat.rows, cvmat.cols))#array([[0.0]*cvmat.width]*cvmat.height) 75 a = zeros((cvmat.rows, cvmat.cols))#array([[0.0]*cvmat.width]*cvmat.height)
75 for i in xrange(cvmat.rows): 76 for i in xrange(cvmat.rows):
76 for j in xrange(cvmat.cols): 77 for j in xrange(cvmat.cols):
77 a[i,j] = cvmat[i,j] 78 a[i,j] = cvmat[i,j]
83 H, mask = cv2.findHomography(srcPoints, dstPoints, method, ransacReprojThreshold) 84 H, mask = cv2.findHomography(srcPoints, dstPoints, method, ransacReprojThreshold)
84 return H 85 return H
85 86
86 def arrayToCvMat(a, t = cv2.cv.CV_64FC1): 87 def arrayToCvMat(a, t = cv2.cv.CV_64FC1):
87 '''Converts a numpy array to an OpenCV CvMat, with default type CV_64FC1.''' 88 '''Converts a numpy array to an OpenCV CvMat, with default type CV_64FC1.'''
89 print('Deprecated, use new interface')
88 cvmat = cv2.cv.CreateMat(a.shape[0], a.shape[1], t) 90 cvmat = cv2.cv.CreateMat(a.shape[0], a.shape[1], t)
89 for i in range(cvmat.rows): 91 for i in range(cvmat.rows):
90 for j in range(cvmat.cols): 92 for j in range(cvmat.cols):
91 cvmat[i,j] = a[i,j] 93 cvmat[i,j] = a[i,j]
92 return cvmat 94 return cvmat
178 frameNum += 1 180 frameNum += 1
179 cv2.destroyAllWindows() 181 cv2.destroyAllWindows()
180 182
181 def printCvMat(cvmat, out = stdout): 183 def printCvMat(cvmat, out = stdout):
182 '''Prints the cvmat to out''' 184 '''Prints the cvmat to out'''
185 print('Deprecated, use new interface')
183 for i in xrange(cvmat.rows): 186 for i in xrange(cvmat.rows):
184 for j in xrange(cvmat.cols): 187 for j in xrange(cvmat.cols):
185 out.write('{0} '.format(cvmat[i,j])) 188 out.write('{0} '.format(cvmat[i,j]))
186 out.write('\n') 189 out.write('\n')
187 190
188 def projectArray(homography, points): 191 def projectArray(homography, points):
189 '''Returns the coordinates of the projected points (format 2xN points) 192 '''Returns the coordinates of the projected points through homography
190 through homography''' 193 (format: array 2xN points)'''
191 from numpy.core import dot 194 from numpy.core import dot
192 from numpy.core.multiarray import array 195 from numpy.core.multiarray import array
193 from numpy.lib.function_base import append 196 from numpy.lib.function_base import append
194 197
195 if points.shape[0] != 2: 198 if points.shape[0] != 2:
214 [y1, y2, ...]]''' 217 [y1, y2, ...]]'''
215 from numpy.core.multiarray import array 218 from numpy.core.multiarray import array
216 return projectArray(homography, array(trajectory)) 219 return projectArray(homography, array(trajectory))
217 220
218 def invertHomography(homography): 221 def invertHomography(homography):
219 'Returns an inverted homography' 222 '''Returns an inverted homography
223 Unnecessary for reprojection over camera image'''
220 from numpy.linalg.linalg import inv 224 from numpy.linalg.linalg import inv
221 invH = inv(homography) 225 invH = inv(homography)
222 invH /= invH[2,2] 226 invH /= invH[2,2]
223 return invH 227 return invH
224 228