diff scripts/undistort-video.py @ 807:52aa03260f03 opencv3

reversed all code to OpenCV 2.4.13
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 10 Jun 2016 15:26:19 -0400
parents 0f6b0f63eb07
children a71455bd8367
line wrap: on
line diff
--- a/scripts/undistort-video.py	Fri Jun 10 12:29:58 2016 -0400
+++ b/scripts/undistort-video.py	Fri Jun 10 15:26:19 2016 -0400
@@ -16,7 +16,7 @@
 parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file')
 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float)
 parser.add_argument('--undistorted-multiplication', dest = 'undistortedImageMultiplication', help = 'undistorted image multiplication', type = float)
-parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int)
+parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int, default = 0)
 parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to save', type = int)
 parser.add_argument('-d', dest = 'destinationDirname', help = 'name of the directory where the undistorted frames are saved')
 parser.add_argument('--encode', dest = 'encodeVideo', help = 'indicate if video is generated at the end (default Xvid)', action = 'store_true')
@@ -40,25 +40,25 @@
         mkdir(destinationDirname)
 
 capture = cv2.VideoCapture(args.videoFilename)
-width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH))
-height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
+width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
+height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))
 [map1, map2] = cvutils.computeUndistortMaps(width, height, args.undistortedImageMultiplication, intrinsicCameraMatrix, args.distortionCoefficients)
 if capture.isOpened():
     ret = True
     frameNum = args.firstFrameNum
-    capture.set(cv2.CAP_PROP_POS_FRAMES, args.firstFrameNum)
+    capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, args.firstFrameNum)
     if args.lastFrameNum is None:
         from sys import maxint
         lastFrameNum = maxint
     else:
         lastFrameNum = args.lastFrameNum
-        nZerosFilename = int(ceil(log10(lastFrameNum)))
-        while ret and frameNum < lastFrameNum:
-            ret, img = capture.read()
-            if ret:
-                img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR)
-                cv2.imwrite(destinationDirname+'undistorted-{{:0{}}}.png'.format(nZerosFilename).format(frameNum), img)
-            frameNum += 1
+    nZerosFilename = int(ceil(log10(lastFrameNum)))
+    while ret and frameNum < lastFrameNum:
+        ret, img = capture.read()
+        if ret:
+            img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR)
+            cv2.imwrite(destinationDirname+'undistorted-{{:0{}}}.png'.format(nZerosFilename).format(frameNum), img)
+        frameNum += 1
 
 if args.encodeVideo:
     print('Encoding the images files in video')