Mercurial Hosting > traffic-intelligence
comparison python/cvutils.py @ 774:b6d3bf350789 dev
minor
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 03 Feb 2016 13:18:02 -0500 |
parents | e92a96f2bdd3 |
children | 5b970a5bc233 |
comparison
equal
deleted
inserted
replaced
773:bf4a1790cfac | 774:b6d3bf350789 |
---|---|
363 frameNum += nFramesStep | 363 frameNum += nFramesStep |
364 if nFramesStep > 1: | 364 if nFramesStep > 1: |
365 capture.set(cv2.CAP_PROP_POS_FRAMES, frameNum) | 365 capture.set(cv2.CAP_PROP_POS_FRAMES, frameNum) |
366 cv2.destroyAllWindows() | 366 cv2.destroyAllWindows() |
367 else: | 367 else: |
368 print 'Cannot load file ' + videoFilename | 368 print('Cannot load file ' + videoFilename) |
369 | 369 |
370 def computeHomographyFromPDTV(camera): | 370 def computeHomographyFromPDTV(camera): |
371 '''Returns the homography matrix at ground level from PDTV camera | 371 '''Returns the homography matrix at ground level from PDTV camera |
372 https://bitbucket.org/hakanardo/pdtv''' | 372 https://bitbucket.org/hakanardo/pdtv''' |
373 # camera = pdtv.load(cameraFilename) | 373 # camera = pdtv.load(cameraFilename) |
398 for i,p in enumerate(t): | 398 for i,p in enumerate(t): |
399 res = undistortedCoordinates(map1, map2, p.x,p.y) | 399 res = undistortedCoordinates(map1, map2, p.x,p.y) |
400 if not isnan(res).any(): | 400 if not isnan(res).any(): |
401 undistortedTrajectory.addPositionXY(res[0], res[1]) | 401 undistortedTrajectory.addPositionXY(res[0], res[1]) |
402 else: | 402 else: |
403 print i,p,res | 403 print('{} {} {}'.format(i,p,res)) |
404 return undistortedTrajectory | 404 return undistortedTrajectory |
405 | 405 |
406 def computeInverseMapping(originalImageSize, map1, map2): | 406 def computeInverseMapping(originalImageSize, map1, map2): |
407 'Computes inverse mapping from maps provided by cv2.initUndistortRectifyMap' | 407 'Computes inverse mapping from maps provided by cv2.initUndistortRectifyMap' |
408 invMap1 = -ones(originalImageSize) | 408 invMap1 = -ones(originalImageSize) |
450 # Find the chess board corners | 450 # Find the chess board corners |
451 ret, corners = cv2.findChessboardCorners(gray, (checkerBoardSize[1],checkerBoardSize[0]), None) | 451 ret, corners = cv2.findChessboardCorners(gray, (checkerBoardSize[1],checkerBoardSize[0]), None) |
452 | 452 |
453 # If found, add object points, image points (after refining them) | 453 # If found, add object points, image points (after refining them) |
454 if ret: | 454 if ret: |
455 print 'Found pattern in '+fname | 455 print('Found pattern in '+fname) |
456 | 456 |
457 if secondPassSearch: | 457 if secondPassSearch: |
458 corners = cv2.cornerSubPix(gray, corners, (11,11), (-1,-1), criteria) | 458 corners = cv2.cornerSubPix(gray, corners, (11,11), (-1,-1), criteria) |
459 | 459 |
460 objpoints.append(objp) | 460 objpoints.append(objp) |
464 if display: | 464 if display: |
465 img = cv2.drawChessboardCorners(img, (checkerBoardSize[1],checkerBoardSize[0]), corners, ret) | 465 img = cv2.drawChessboardCorners(img, (checkerBoardSize[1],checkerBoardSize[0]), corners, ret) |
466 if img is not None: | 466 if img is not None: |
467 cv2.imshow('img',img) | 467 cv2.imshow('img',img) |
468 cv2.waitKey(0) | 468 cv2.waitKey(0) |
469 | 469 else: |
470 print('Pattern not found in '+fname) | |
470 ## Close up image loading and calibrate | 471 ## Close up image loading and calibrate |
471 cv2.destroyAllWindows() | 472 cv2.destroyAllWindows() |
472 if len(objpoints) == 0 or len(imgpoints) == 0: | 473 if len(objpoints) == 0 or len(imgpoints) == 0: |
473 return False | 474 return False |
474 try: | 475 try: |