Mercurial Hosting > traffic-intelligence
diff python/cvutils.py @ 227:b7612c6d5702
cleaned the code
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 27 Jun 2012 09:52:06 -0400 |
parents | 91197f6a03fe |
children | ab1a11176d7b |
line wrap: on
line diff
--- a/python/cvutils.py Tue Jun 26 10:15:11 2012 -0400 +++ b/python/cvutils.py Wed Jun 27 09:52:06 2012 -0400 @@ -92,14 +92,15 @@ for i in range(0, last-1): cv2.line(img, positions[i].asint().astuple(), positions[i+1].asint().astuple(), color) - def playVideo(filename, firstFrame = 0): + def playVideo(filename, firstFrameNum = 0): '''Plays the video''' capture = cv2.VideoCapture(filename) if capture.isOpened(): key = -1 - frameNum = 1 - capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrame) - while key!= 113: # 'q' + ret = True + frameNum = firstFrameNum + capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) + while ret and key!= 113: # 'q' ret, img = capture.read() if ret: print('frame {0}'.format(frameNum)) @@ -128,16 +129,19 @@ images.append(img) return images - def displayTrajectories(videoFilename, objects, homography = None): + def displayTrajectories(videoFilename, objects, homography = None, firstFrameNum = 0): '''Displays the objects overlaid frame by frame over the video ''' capture = cv2.VideoCapture(videoFilename) if capture.isOpened(): key = -1 - frameNum = 0 - while key!= 113: # 'q' + ret = True + frameNum = firstFrameNum + capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) + while ret and key!= 113: # 'q' + print('capture') ret, img = capture.read() if ret: - print(frameNum) + print('frame {0}'.format(frameNum)) for obj in objects: if obj.existsAtInstant(frameNum): if obj.getFirstInstant() == frameNum: