Mercurial Hosting > traffic-intelligence
comparison scripts/compute-homography.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 | fe34c0f79c32 |
comparison
equal
deleted
inserted
replaced
638:852f5de42d01 | 639:4e7925cb4f8f |
---|---|
79 homography = np.array([]) | 79 homography = np.array([]) |
80 if args.pointCorrespondencesFilename is not None: | 80 if args.pointCorrespondencesFilename is not None: |
81 worldPts, videoPts = cvutils.loadPointCorrespondences(args.pointCorrespondencesFilename) | 81 worldPts, videoPts = cvutils.loadPointCorrespondences(args.pointCorrespondencesFilename) |
82 homography, mask = cv2.findHomography(videoPts, worldPts) # method=0, ransacReprojThreshold=3 | 82 homography, mask = cv2.findHomography(videoPts, worldPts) # method=0, ransacReprojThreshold=3 |
83 elif args.tsaiCameraFilename is not None: # hack using PDTV | 83 elif args.tsaiCameraFilename is not None: # hack using PDTV |
84 from StringIO import StringIO | |
85 from pdtv import TsaiCamera | |
86 import yaml | |
84 f = storage.openCheck(args.tsaiCameraFilename, quitting = True) | 87 f = storage.openCheck(args.tsaiCameraFilename, quitting = True) |
85 content = storage.getLines(f) | 88 content = storage.getLines(f) |
86 outFilename = '/tmp/camera.yaml' | 89 #out.write('data_class: TsaiCamera\n') |
87 out = storage.openCheck(outFilename, 'w') | 90 yamlContent = ''.join([l.replace(' f:', 'f:').replace(' k:', 'k:').replace(',','.')+'\n' for l in content]) |
88 out.write('data_class: TsaiCamera\n') | 91 cameraData = yaml.load(StringIO(yamlContent)) |
89 for l in content: | 92 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']) |
90 out.write(l.replace(' f:', 'f:').replace(' k:', 'k:').replace(',','.')+'\n') | 93 homography = cvutils.computeHomographyFromPDTV(camera) |
91 out.close() | |
92 homography = cvutils.computeHomographyFromPDTV(outFilename) | |
93 elif args.videoFrameFilename is not None and args.worldFilename is not None: | 94 elif args.videoFrameFilename is not None and args.worldFilename is not None: |
94 worldImg = plt.imread(args.worldFilename) | 95 worldImg = plt.imread(args.worldFilename) |
95 videoImg = plt.imread(args.videoFrameFilename) | 96 videoImg = plt.imread(args.videoFrameFilename) |
96 if args.undistort: | 97 if args.undistort: |
97 [map1, map2] = cvutils.computeUndistortMaps(videoImg.shape[1], videoImg.shape[0], args.undistortedImageMultiplication, np.loadtxt(args.intrinsicCameraMatrixFilename), args.distortionCoefficients) | 98 [map1, map2] = cvutils.computeUndistortMaps(videoImg.shape[1], videoImg.shape[0], args.undistortedImageMultiplication, np.loadtxt(args.intrinsicCameraMatrixFilename), args.distortionCoefficients) |