comparison 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
comparison
equal deleted inserted replaced
149:0f552c8b1650 150:404f3cade05f
56 for j in range(cvmat.cols): 56 for j in range(cvmat.cols):
57 cvmat[i,j] = a[i,j] 57 cvmat[i,j] = a[i,j]
58 return cvmat 58 return cvmat
59 59
60 def playVideo(filename): 60 def playVideo(filename):
61 '''Plays the video'''
61 capture = cv2.VideoCapture(filename) 62 capture = cv2.VideoCapture(filename)
62 if capture.isOpened(): 63 if capture.isOpened():
63 key = -1 64 key = -1
64 while key!= 1048689: # 'q' 65 while key!= 1048689: # 'q'
65 ret, img = capture.read() 66 ret, img = capture.read()
66 if ret: 67 if ret:
67 cv2.imshow('frame', img) 68 cv2.imshow('frame', img)
68 key = cv2.waitKey(5) 69 key = cv2.waitKey(5)
69 70
71 def getImagesFromVideo(filename, nImages = 1):
72 '''Returns nImages images from the video sequence'''
73 images = []
74 capture = cv2.VideoCapture(filename)
75 if capture.isOpened():
76 ret = False
77 while len(images)<nImages:
78 while not ret:
79 ret, img = capture.read()
80 if img.size>0:
81 images.append(img)
82 return images
70 83
71 def printCvMat(cvmat, out = stdout): 84 def printCvMat(cvmat, out = stdout):
72 '''Prints the cvmat to out''' 85 '''Prints the cvmat to out'''
73 for i in xrange(cvmat.rows): 86 for i in xrange(cvmat.rows):
74 for j in xrange(cvmat.cols): 87 for j in xrange(cvmat.cols):