Mercurial Hosting > traffic-intelligence
changeset 820:e73e7b644428
generalized play-video for several files (already synchronized
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 22 Jun 2016 15:23:20 -0400 |
parents | fc8b3ce629d1 |
children | 26daf35180ad |
files | python/cvutils.py scripts/play-video.py |
diffstat | 2 files changed, 26 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/python/cvutils.py Wed Jun 22 14:51:00 2016 -0400 +++ b/python/cvutils.py Wed Jun 22 15:23:20 2016 -0400 @@ -146,39 +146,50 @@ newCameraMatrix[1,2] = newImgSize[1]/2. return cv2.initUndistortRectifyMap(intrinsicCameraMatrix, array(distortionCoefficients), identity(3), newCameraMatrix, newImgSize, cv2.CV_32FC1) - def playVideo(filename, firstFrameNum = 0, frameRate = -1, interactive = False, printFrames = True, text = None, rescale = 1., step = 1): - '''Plays the video''' - windowName = 'frame' + def playVideo(filenames, windowNames = None, firstFrameNum = 0, frameRate = -1, interactive = False, printFrames = True, text = None, rescale = 1., step = 1): + '''Plays the video(s)''' + if windowNames is None: + windowNames = ['frame{}'.format(i) for i in xrange(len(filenames))] wait = 5 if rescale == 1.: - cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) + for windowName in windowNames: + cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) if frameRate > 0: wait = int(round(1000./frameRate)) if interactive: wait = 0 - capture = cv2.VideoCapture(filename) - if capture.isOpened(): + captures = [cv2.VideoCapture(fn) for fn in filenames] + if array([cap.isOpened() for cap in captures]).all(): key = -1 ret = True frameNum = firstFrameNum - capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) + for cap in captures: + cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) while ret and not quitKey(key): - ret, img = capture.read() - if ret: + rets = [] + images = [] + for cap in captures: + ret, img = cap.read() + rets.append(ret) + images.append(img) + if array(rets).all(): if printFrames: print('frame {0}'.format(frameNum)) - if text is not None: - cv2.putText(img, text, (10,50), cv2.FONT_HERSHEY_PLAIN, 1, cvRed) - cv2.imshow('frame', img)#cvImshow(windowName, img, rescale) + #if text is not None: + # cv2.putText(img, text, (10,50), cv2.FONT_HERSHEY_PLAIN, 1, cvRed) + for i in xrange(1, len(filenames)): + cvImshow(windowNames[i], images[i], rescale) + cvImshow(windowNames[0], images[0], rescale) # cv2.imshow('frame', img) key = cv2.waitKey(wait) if saveKey(key): cv2.imwrite('image-{}.png'.format(frameNum), img) frameNum += step if step > 1: - capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, frameNum) + for cap in captures: + cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, frameNum) cv2.destroyAllWindows() else: - print('Video capture for {} failed'.format(filename)) + print('Video captures for {} failed'.format(filenames)) def infoVideo(filename): '''Provides all available info on video '''
--- a/scripts/play-video.py Wed Jun 22 14:51:00 2016 -0400 +++ b/scripts/play-video.py Wed Jun 22 15:23:20 2016 -0400 @@ -21,4 +21,4 @@ if args.frameRate is not None: frameRate = args.frameRate -cvutils.playVideo(args.videoFilename, firstFrameNum, frameRate, rescale = args.rescale, step = args.step) +cvutils.playVideo([args.videoFilename], None, firstFrameNum, frameRate, rescale = args.rescale, step = args.step)