comparison python/cvutils.py @ 639:4e7925cb4f8f

modified tsai camera homography computation to avoid using os dependent temporary files
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 09 Apr 2015 13:11:25 +0200
parents 852f5de42d01
children 51269511229b
comparison
equal deleted inserted replaced
638:852f5de42d01 639:4e7925cb4f8f
275 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, frameNum) 275 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, frameNum)
276 cv2.destroyAllWindows() 276 cv2.destroyAllWindows()
277 else: 277 else:
278 print 'Cannot load file ' + videoFilename 278 print 'Cannot load file ' + videoFilename
279 279
280 def computeHomographyFromPDTV(cameraFilename): 280 def computeHomographyFromPDTV(camera):
281 '''Returns the homography matrix at ground level from PDTV format 281 '''Returns the homography matrix at ground level from PDTV camera
282 https://bitbucket.org/hakanardo/pdtv''' 282 https://bitbucket.org/hakanardo/pdtv'''
283 import pdtv
284 from numpy import array 283 from numpy import array
285 camera = pdtv.load(cameraFilename) 284 # camera = pdtv.load(cameraFilename)
286 srcPoints = [[x,y] for x, y in zip([1.,2.,2.,1.],[1.,1.,2.,2.])] # need floats!! 285 srcPoints = [[x,y] for x, y in zip([1.,2.,2.,1.],[1.,1.,2.,2.])] # need floats!!
287 dstPoints = [] 286 dstPoints = []
288 for srcPoint in srcPoints: 287 for srcPoint in srcPoints:
289 projected = camera.image_to_world(tuple(srcPoint)) 288 projected = camera.image_to_world(tuple(srcPoint))
290 dstPoints.append([projected[0], projected[1]]) 289 dstPoints.append([projected[0], projected[1]])
421 420
422 if points.shape[0] != 2: 421 if points.shape[0] != 2:
423 raise Exception('points of dimension {0} {1}'.format(points.shape[0], points.shape[1])) 422 raise Exception('points of dimension {0} {1}'.format(points.shape[0], points.shape[1]))
424 423
425 if (homography is not None) and homography.size>0: 424 if (homography is not None) and homography.size>0:
425 #alternatively, on could use cv2.convertpointstohomogeneous and other conversion to/from homogeneous coordinates
426 augmentedPoints = append(points,[[1]*points.shape[1]], 0) 426 augmentedPoints = append(points,[[1]*points.shape[1]], 0)
427 prod = dot(homography, augmentedPoints) 427 prod = dot(homography, augmentedPoints)
428 return prod[0:2]/prod[2] 428 return prod[0:2]/prod[2]
429 else: 429 else:
430 return points 430 return points