diff python/cvutils.py @ 381:387cc0142211

script to replay event annotations
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 19 Jul 2013 11:58:35 -0400
parents 22ddb8f85495
children 6da9cf5609aa
line wrap: on
line diff
--- a/python/cvutils.py	Fri Jul 19 09:11:57 2013 -0400
+++ b/python/cvutils.py	Fri Jul 19 11:58:35 2013 -0400
@@ -98,11 +98,13 @@
         for i in range(0, last-1):
             cv2.line(img, positions[i].asint().astuple(), positions[i+1].asint().astuple(), color)
 
-    def playVideo(filename, firstFrameNum = 0, frameRate = -1):
+    def playVideo(filename, firstFrameNum = 0, frameRate = -1, interactive = False, printFrames = True, text = None):
         '''Plays the video'''
         wait = 5
         if frameRate > 0:
             wait = int(round(1000./frameRate))
+        if interactive:
+            wait = 0
         capture = cv2.VideoCapture(filename)
         if capture.isOpened():
             key = -1
@@ -112,8 +114,11 @@
             while ret and not quitKey(key):
                 ret, img = capture.read()
                 if ret:
-                    print('frame {0}'.format(frameNum))
+                    if printFrames:
+                        print('frame {0}'.format(frameNum))
                     frameNum+=1
+                    if text != None:
+                       cv2.putText(img, text, (10,50), cv2.FONT_HERSHEY_PLAIN, 1, cvRed) 
                     cv2.imshow('frame', img)
                     key = cv2.waitKey(wait)
             cv2.destroyAllWindows()
@@ -139,7 +144,7 @@
                         images.append(img)
         return images
 
-    def displayTrajectories(videoFilename, objects, homography = None, firstFrameNum = 0, lastFrameNumArg = None):
+    def displayTrajectories(videoFilename, objects, homography = None, firstFrameNum = 0, lastFrameNumArg = None, printFrames = True):
         '''Displays the objects overlaid frame by frame over the video '''
         capture = cv2.VideoCapture(videoFilename)
         if capture.isOpened():
@@ -155,7 +160,8 @@
             while ret and not quitKey(key) and frameNum < lastFrameNum:
                 ret, img = capture.read()
                 if ret:
-                    print('frame {0}'.format(frameNum))
+                    if printFrames:
+                        print('frame {0}'.format(frameNum))
                     for obj in objects:
                         if obj.existsAtInstant(frameNum):
                             if not hasattr(obj, 'projectedPositions'):