Mercurial Hosting > traffic-intelligence
changeset 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 | fe34c0f79c32 |
files | python/cvutils.py scripts/compute-homography.py |
diffstat | 2 files changed, 12 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/python/cvutils.py Wed Apr 08 16:07:15 2015 +0200 +++ b/python/cvutils.py Thu Apr 09 13:11:25 2015 +0200 @@ -277,12 +277,11 @@ else: print 'Cannot load file ' + videoFilename - def computeHomographyFromPDTV(cameraFilename): - '''Returns the homography matrix at ground level from PDTV format + def computeHomographyFromPDTV(camera): + '''Returns the homography matrix at ground level from PDTV camera https://bitbucket.org/hakanardo/pdtv''' - import pdtv from numpy import array - camera = pdtv.load(cameraFilename) + # 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: @@ -423,6 +422,7 @@ raise Exception('points of dimension {0} {1}'.format(points.shape[0], points.shape[1])) if (homography is not None) and homography.size>0: + #alternatively, on could use cv2.convertpointstohomogeneous and other conversion to/from homogeneous coordinates augmentedPoints = append(points,[[1]*points.shape[1]], 0) prod = dot(homography, augmentedPoints) return prod[0:2]/prod[2]
--- a/scripts/compute-homography.py Wed Apr 08 16:07:15 2015 +0200 +++ b/scripts/compute-homography.py Thu Apr 09 13:11:25 2015 +0200 @@ -81,15 +81,16 @@ worldPts, videoPts = cvutils.loadPointCorrespondences(args.pointCorrespondencesFilename) homography, mask = cv2.findHomography(videoPts, worldPts) # method=0, ransacReprojThreshold=3 elif args.tsaiCameraFilename is not None: # hack using PDTV + from StringIO import StringIO + from pdtv import TsaiCamera + import yaml f = storage.openCheck(args.tsaiCameraFilename, quitting = True) content = storage.getLines(f) - outFilename = '/tmp/camera.yaml' - out = storage.openCheck(outFilename, 'w') - out.write('data_class: TsaiCamera\n') - for l in content: - out.write(l.replace(' f:', 'f:').replace(' k:', 'k:').replace(',','.')+'\n') - out.close() - homography = cvutils.computeHomographyFromPDTV(outFilename) + #out.write('data_class: TsaiCamera\n') + yamlContent = ''.join([l.replace(' f:', 'f:').replace(' k:', 'k:').replace(',','.')+'\n' for l in content]) + cameraData = yaml.load(StringIO(yamlContent)) + camera = TsaiCamera(Cx=cameraData['Cx'], Cy=cameraData['Cy'], Sx=cameraData['Sx'], Tx=cameraData['Tx'], Ty=cameraData['Ty'], Tz=cameraData['Tz'], dx=cameraData['dx'], dy=cameraData['dy'], f=cameraData['f'], k=cameraData['k'], r1=cameraData['r1'], r2=cameraData['r2'], r3=cameraData['r3'], r4=cameraData['r4'], r5=cameraData['r5'], r6=cameraData['r6'], r7=cameraData['r7'], r8=cameraData['r8'], r9=cameraData['r9']) + homography = cvutils.computeHomographyFromPDTV(camera) elif args.videoFrameFilename is not None and args.worldFilename is not None: worldImg = plt.imread(args.worldFilename) videoImg = plt.imread(args.videoFrameFilename)