Mercurial Hosting > traffic-intelligence
diff python/cvutils.py @ 150:404f3cade05f
added python function to get image frames from video filenames
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 01 Sep 2011 18:37:35 -0400 |
parents | 0f552c8b1650 |
children | 4af774bb186d |
line wrap: on
line diff
--- a/python/cvutils.py Thu Sep 01 18:33:38 2011 -0400 +++ b/python/cvutils.py Thu Sep 01 18:37:35 2011 -0400 @@ -58,6 +58,7 @@ return cvmat def playVideo(filename): + '''Plays the video''' capture = cv2.VideoCapture(filename) if capture.isOpened(): key = -1 @@ -67,6 +68,18 @@ cv2.imshow('frame', img) key = cv2.waitKey(5) + def getImagesFromVideo(filename, nImages = 1): + '''Returns nImages images from the video sequence''' + images = [] + capture = cv2.VideoCapture(filename) + if capture.isOpened(): + ret = False + while len(images)<nImages: + while not ret: + ret, img = capture.read() + if img.size>0: + images.append(img) + return images def printCvMat(cvmat, out = stdout): '''Prints the cvmat to out'''