# HG changeset patch # User Nicolas Saunier # Date 1464662964 14400 # Node ID 5b99b676265e7c2e6737e4b515a94cf1f06b03c7 # Parent 2ffaf1a7cde9ebbfc1a1c6a7953cfb38a55a9663 modified to get images very time step diff -r 2ffaf1a7cde9 -r 5b99b676265e python/cvutils.py --- a/python/cvutils.py Mon May 23 23:55:06 2016 -0400 +++ b/python/cvutils.py Mon May 30 22:49:24 2016 -0400 @@ -218,19 +218,19 @@ else: print('Video capture for {} failed'.format(filename)) - def getImagesFromVideo(videoFilename, firstFrameNum = 0, nFrames = 1, saveImage = False, outputPrefix = 'image'): + def getImagesFromVideo(videoFilename, firstFrameNum = 0, lastFrameNum = 1, step = 1, saveImage = False, outputPrefix = 'image'): '''Returns nFrames images from the video sequence''' images = [] capture = cv2.VideoCapture(videoFilename) if capture.isOpened(): rawCount = capture.get(cv2.CAP_PROP_FRAME_COUNT) if rawCount < 0: - rawCount = firstFrameNum+nFrames+1 + rawCount = lastFrameNum+1 nDigits = int(floor(log10(rawCount)))+1 ret = False capture.set(cv2.CAP_PROP_POS_FRAMES, firstFrameNum) - imgNum = 0 - while imgNum0: if saveImage: - imgNumStr = format(firstFrameNum+imgNum, '0{}d'.format(nDigits)) - cv2.imwrite(outputPrefix+imgNumStr+'.png', img) + frameNumStr = format(frameNum, '0{}d'.format(nDigits)) + cv2.imwrite(outputPrefix+frameNumStr+'.png', img) else: images.append(img) - imgNum +=1 + frameNum +=step + if step > 1: + capture.set(cv2.CAP_PROP_POS_FRAMES, frameNum) capture.release() else: print('Video capture for {} failed'.format(videoFilename))