comparison 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
comparison
equal deleted inserted replaced
806:c6f497291fd8 807:52aa03260f03
14 14
15 parser.add_argument('-i', dest = 'videoFilename', help = 'filename of the video sequence') 15 parser.add_argument('-i', dest = 'videoFilename', help = 'filename of the video sequence')
16 parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file') 16 parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file')
17 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float) 17 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float)
18 parser.add_argument('--undistorted-multiplication', dest = 'undistortedImageMultiplication', help = 'undistorted image multiplication', type = float) 18 parser.add_argument('--undistorted-multiplication', dest = 'undistortedImageMultiplication', help = 'undistorted image multiplication', type = float)
19 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int) 19 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int, default = 0)
20 parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to save', type = int) 20 parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to save', type = int)
21 parser.add_argument('-d', dest = 'destinationDirname', help = 'name of the directory where the undistorted frames are saved') 21 parser.add_argument('-d', dest = 'destinationDirname', help = 'name of the directory where the undistorted frames are saved')
22 parser.add_argument('--encode', dest = 'encodeVideo', help = 'indicate if video is generated at the end (default Xvid)', action = 'store_true') 22 parser.add_argument('--encode', dest = 'encodeVideo', help = 'indicate if video is generated at the end (default Xvid)', action = 'store_true')
23 parser.add_argument('--fps', dest = 'fps', help = 'frame per second of the output video file if encoding', type = float, default = 30) 23 parser.add_argument('--fps', dest = 'fps', help = 'frame per second of the output video file if encoding', type = float, default = 30)
24 parser.add_argument('--bitrate', dest = 'bitrate', help = 'bitrate of the output video file if encoding', type = int, default = 5000) 24 parser.add_argument('--bitrate', dest = 'bitrate', help = 'bitrate of the output video file if encoding', type = int, default = 5000)
38 destinationDirname = args.destinationDirname 38 destinationDirname = args.destinationDirname
39 if not path.exists(destinationDirname): 39 if not path.exists(destinationDirname):
40 mkdir(destinationDirname) 40 mkdir(destinationDirname)
41 41
42 capture = cv2.VideoCapture(args.videoFilename) 42 capture = cv2.VideoCapture(args.videoFilename)
43 width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)) 43 width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
44 height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)) 44 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))
45 [map1, map2] = cvutils.computeUndistortMaps(width, height, args.undistortedImageMultiplication, intrinsicCameraMatrix, args.distortionCoefficients) 45 [map1, map2] = cvutils.computeUndistortMaps(width, height, args.undistortedImageMultiplication, intrinsicCameraMatrix, args.distortionCoefficients)
46 if capture.isOpened(): 46 if capture.isOpened():
47 ret = True 47 ret = True
48 frameNum = args.firstFrameNum 48 frameNum = args.firstFrameNum
49 capture.set(cv2.CAP_PROP_POS_FRAMES, args.firstFrameNum) 49 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, args.firstFrameNum)
50 if args.lastFrameNum is None: 50 if args.lastFrameNum is None:
51 from sys import maxint 51 from sys import maxint
52 lastFrameNum = maxint 52 lastFrameNum = maxint
53 else: 53 else:
54 lastFrameNum = args.lastFrameNum 54 lastFrameNum = args.lastFrameNum
55 nZerosFilename = int(ceil(log10(lastFrameNum))) 55 nZerosFilename = int(ceil(log10(lastFrameNum)))
56 while ret and frameNum < lastFrameNum: 56 while ret and frameNum < lastFrameNum:
57 ret, img = capture.read() 57 ret, img = capture.read()
58 if ret: 58 if ret:
59 img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) 59 img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR)
60 cv2.imwrite(destinationDirname+'undistorted-{{:0{}}}.png'.format(nZerosFilename).format(frameNum), img) 60 cv2.imwrite(destinationDirname+'undistorted-{{:0{}}}.png'.format(nZerosFilename).format(frameNum), img)
61 frameNum += 1 61 frameNum += 1
62 62
63 if args.encodeVideo: 63 if args.encodeVideo:
64 print('Encoding the images files in video') 64 print('Encoding the images files in video')
65 from subprocess import check_call 65 from subprocess import check_call
66 from storage import openCheck 66 from storage import openCheck