Mercurial Hosting > traffic-intelligence
comparison python/cvutils.py @ 638:852f5de42d01
added functionality to read Aliaksei Tsai camera model data
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 08 Apr 2015 16:07:15 +0200 |
parents | 3058e00887bc |
children | 4e7925cb4f8f |
comparison
equal
deleted
inserted
replaced
637:c9a0b72979fd | 638:852f5de42d01 |
---|---|
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, method=0, ransacReprojThreshold=3.0): | 280 def computeHomographyFromPDTV(cameraFilename): |
281 '''Returns the homography matrix at ground level from PDTV format | 281 '''Returns the homography matrix at ground level from PDTV format |
282 https://bitbucket.org/hakanardo/pdtv''' | 282 https://bitbucket.org/hakanardo/pdtv''' |
283 import pdtv | 283 import pdtv |
284 from numpy import array | 284 from numpy import array |
285 camera = pdtv.load(cameraFilename) | 285 camera = pdtv.load(cameraFilename) |
286 srcPoints = [[x,y] for x, y in zip([1.,2.,2.,1.],[1.,1.,2.,2.])] # need floats!! | 286 srcPoints = [[x,y] for x, y in zip([1.,2.,2.,1.],[1.,1.,2.,2.])] # need floats!! |
287 dstPoints = [] | 287 dstPoints = [] |
288 for srcPoint in srcPoints: | 288 for srcPoint in srcPoints: |
289 projected = camera.image_to_world(tuple(srcPoint)) | 289 projected = camera.image_to_world(tuple(srcPoint)) |
290 dstPoints.append([projected[0], projected[1]]) | 290 dstPoints.append([projected[0], projected[1]]) |
291 H, mask = cv2.findHomography(array(srcPoints), array(dstPoints), method, ransacReprojThreshold) | 291 H, mask = cv2.findHomography(array(srcPoints), array(dstPoints), method = 0) # No need for different methods for finding homography |
292 return H | 292 return H |
293 | 293 |
294 def undistortedCoordinates(map1, map2, x, y, maxDistance = 1.): | 294 def undistortedCoordinates(map1, map2, x, y, maxDistance = 1.): |
295 '''Returns the coordinates of a point in undistorted image | 295 '''Returns the coordinates of a point in undistorted image |
296 map1 and map2 are the mapping functions from undistorted image | 296 map1 and map2 are the mapping functions from undistorted image |