Mercurial > hg > nsaunier > traffic-intelligence
comparison python/cvutils.py @ 978:184f1dd307f9
corrected print and exception statements for Python 3
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 08 Feb 2018 05:53:50 -0500 |
| parents | 5d788d2e8ffc |
| children | c3e690c5536e |
comparison
equal
deleted
inserted
replaced
| 977:9c27a0315c4d | 978:184f1dd307f9 |
|---|---|
| 14 skimageAvailable = True | 14 skimageAvailable = True |
| 15 except ImportError: | 15 except ImportError: |
| 16 print('Scikit-image library could not be loaded (HoG-based classification methods will not be available)') | 16 print('Scikit-image library could not be loaded (HoG-based classification methods will not be available)') |
| 17 skimageAvailable = False | 17 skimageAvailable = False |
| 18 | 18 |
| 19 from sys import stdout, maxint | 19 from sys import stdout |
| 20 from os import listdir | 20 from os import listdir |
| 21 from copy import deepcopy | 21 from copy import deepcopy |
| 22 from math import floor, log10, ceil | 22 from math import floor, log10, ceil |
| 23 | 23 |
| 24 from numpy import dot, array, append, float32, loadtxt, savetxt, append, zeros, ones, identity, abs as npabs, logical_and, unravel_index, sum as npsum, isnan, mgrid, median, floor as npfloor, ceil as npceil | 24 from numpy import dot, array, append, float32, loadtxt, savetxt, append, zeros, ones, identity, abs as npabs, logical_and, unravel_index, sum as npsum, isnan, mgrid, median, floor as npfloor, ceil as npceil |
| 313 key = -1 | 313 key = -1 |
| 314 ret = True | 314 ret = True |
| 315 frameNum = firstFrameNum | 315 frameNum = firstFrameNum |
| 316 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) | 316 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) |
| 317 if lastFrameNumArg is None: | 317 if lastFrameNumArg is None: |
| 318 lastFrameNum = maxint | 318 lastFrameNum = float("inf") |
| 319 else: | 319 else: |
| 320 lastFrameNum = lastFrameNumArg | 320 lastFrameNum = lastFrameNumArg |
| 321 if nZerosFilenameArg is None: | 321 if nZerosFilenameArg is None: |
| 322 nZerosFilename = int(ceil(log10(lastFrameNum))) | 322 nZerosFilename = int(ceil(log10(lastFrameNum))) |
| 323 else: | 323 else: |
| 500 flags += cv2.cv.CV_CALIB_ZERO_TANGENT_DIST | 500 flags += cv2.cv.CV_CALIB_ZERO_TANGENT_DIST |
| 501 ret, camera_matrix, dist_coeffs, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None, flags = flags) | 501 ret, camera_matrix, dist_coeffs, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None, flags = flags) |
| 502 except NameError: | 502 except NameError: |
| 503 return None | 503 return None |
| 504 savetxt('intrinsic-camera.txt', camera_matrix) | 504 savetxt('intrinsic-camera.txt', camera_matrix) |
| 505 print 'error: {}'.format(ret) | 505 print('error: {}'.format(ret)) |
| 506 return camera_matrix, dist_coeffs | 506 return camera_matrix, dist_coeffs |
| 507 | 507 |
| 508 def undistortImage(img, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1., interpolation=cv2.INTER_LINEAR): | 508 def undistortImage(img, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1., interpolation=cv2.INTER_LINEAR): |
| 509 '''Undistorts the image passed in argument''' | 509 '''Undistorts the image passed in argument''' |
| 510 width = img.shape[1] | 510 width = img.shape[1] |
