comparison python/cvutils.py @ 468:5304299e53a5

added coordinate undistortion function
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 06 Mar 2014 15:01:19 -0500
parents 17185fe77316
children a50c026fdf14
comparison
equal deleted inserted replaced
466:e891a41c6c75 468:5304299e53a5
263 projected = camera.image_to_world(tuple(srcPoint)) 263 projected = camera.image_to_world(tuple(srcPoint))
264 dstPoints.append([projected[0], projected[1]]) 264 dstPoints.append([projected[0], projected[1]])
265 H, mask = cv2.findHomography(array(srcPoints), array(dstPoints), method, ransacReprojThreshold) 265 H, mask = cv2.findHomography(array(srcPoints), array(dstPoints), method, ransacReprojThreshold)
266 return H 266 return H
267 267
268 def correctedCoordinates(x,y, map1, map2):
269 '''Returns the coordinates of a point in undistorted image
270 map1 and map2 are the mapping functions from undistorted image
271 to distorted (original image)
272 map1(x,y) = originalx, originaly'''
273 from numpy import abs, logical_and, unravel_index, dot, sum
274 from matplotlib.mlab import find
275 distx = abs(map1-x)
276 disty = abs(map2-y)
277 indices = logical_and(distx<1, disty<1)
278 closeCoordinates = unravel_index(find(indices), distx.shape) # returns i,j, ie y,x
279 xWeights = 1-distx[indices]
280 yWeights = 1-disty[indices]
281 return dot(xWeights, closeCoordinates[1])/sum(xWeights), dot(yWeights, closeCoordinates[0])/sum(yWeights)
282
268 283
269 def printCvMat(cvmat, out = stdout): 284 def printCvMat(cvmat, out = stdout):
270 '''Prints the cvmat to out''' 285 '''Prints the cvmat to out'''
271 print('Deprecated, use new interface') 286 print('Deprecated, use new interface')
272 for i in xrange(cvmat.rows): 287 for i in xrange(cvmat.rows):